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

Allow lai streams with FATES #2054

Merged
merged 40 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
946a8a0
initial changes
Jul 10, 2023
1d649da
add test
Jul 10, 2023
dbf0bff
fix bld script?
Jul 10, 2023
536e206
add test info
Jul 10, 2023
be38269
fix perl syntax
Jul 10, 2023
0c642db
add check for lai streams
Jul 10, 2023
e24ffb2
Merge branch 'master' into fates_lai_streams
adrifoster Jul 11, 2023
583ed09
update lai init
adrifoster Jul 11, 2023
e629893
get rid of print statements
Jul 12, 2023
412cff5
don't use soil moisture streams
Jul 12, 2023
c2b9677
update test
Jul 12, 2023
6ec2058
whitespace
Jul 12, 2023
578b0bf
fix comment for new fates test
Jul 16, 2023
80977d7
we can now run FATES with 1 deg in SP mode
Jul 20, 2023
80ba5e8
update to use constant
Jul 20, 2023
d40dd88
need to check lai streams
Jul 20, 2023
dbcbe05
need to check lai streams
Jul 20, 2023
753f97d
move tolerance to constants file
Jul 25, 2023
32a334a
don't do prescribed soil moisture
Jul 26, 2023
99c4e66
Merge branch 'master' into fates_lai_streams
Aug 14, 2023
2ef13f5
add check to namelist
Aug 24, 2023
392dae6
update error note
Aug 24, 2023
0870004
make separate error
Aug 24, 2023
ae3f738
get rid of use_lai_streams=true, user_nl_clm empty to deleted
Aug 24, 2023
3d00c3f
Merge branch 'master' into fates_lai_streams
adrifoster Aug 24, 2023
1ee1979
remove cn/cndv
Aug 24, 2023
b5e265d
Merge branch 'fates_lai_streams' of https://github.com/adrifoster/CTS…
Aug 24, 2023
23038c9
Merge branch 'master' into fates_lai_streams
adrifoster Sep 8, 2023
d25281d
update fates externals
adrifoster Sep 8, 2023
bed606d
fix merge conflict error
adrifoster Sep 8, 2023
278ce01
update changelog
Sep 11, 2023
b56f919
updated date
Sep 11, 2023
385ebee
update Changelog date
Sep 12, 2023
24dee00
add bldnamelist tests
Sep 12, 2023
1fb58be
trying to fix
Sep 12, 2023
ec938f0
trying to fix issues
adrifoster Sep 12, 2023
79c8a85
fix typo
adrifoster Sep 12, 2023
451cbc6
update changelog date
Sep 12, 2023
6bfb9b0
remove print statement
Sep 12, 2023
175fab0
add issue discription in changelog
Sep 12, 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
2 changes: 1 addition & 1 deletion Externals_CLM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local_path = src/fates
protocol = git
repo_url = https://github.com/NGEET/fates
tag = sci.1.67.1_api.27.0.0
tag = sci.1.67.2_api.27.0.0
required = True

[externals_description]
Expand Down
22 changes: 14 additions & 8 deletions bld/CLMBuildNamelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3890,8 +3890,10 @@ sub setup_logic_lai_streams {
if ( &value_is_true($nl_flags->{'use_crop'}) && &value_is_true($nl->get_value('use_lai_streams')) ) {
$log->fatal_error("turning use_lai_streams on is incompatable with use_crop set to true.");
}
if ( $nl_flags->{'bgc_mode'} eq "sp" ) {

if ( ($nl_flags->{'bgc_mode'} eq "sp" || $nl_flags->{'bgc_mode'} eq "fates") ) {
if ( $nl_flags->{'bgc_mode'} eq "fates" && ! &value_is_true($nl->get_value('use_fates_sp')) && &value_is_true($nl->get_value('use_lai_streams'))) {
$log->fatal_error("Must have use_fates_sp turned on to run FATES with LAI streams.");
}
if ( &value_is_true($nl->get_value('use_lai_streams')) ) {
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'use_lai_streams');
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'lai_mapalgo',
Expand All @@ -3917,15 +3919,19 @@ sub setup_logic_lai_streams {
}
}
} else {
# If bgc is CN/CNDV then make sure none of the LAI settings are set
if ( defined($nl->get_value('stream_year_first_lai')) ||
defined($nl->get_value('stream_year_last_lai')) ||
defined($nl->get_value('model_year_align_lai')) ||
defined($nl->get_value('lai_tintalgo' )) ||
# If bgc is BGC/BGCDV then make sure none of the LAI settings are set
if ( &value_is_true($nl->get_value('use_lai_streams'))) {
$log->fatal_error("When bgc is NOT SP use_lai_streams cannot be .true.\n" .
adrifoster marked this conversation as resolved.
Show resolved Hide resolved
"(eg. don't use this option with BGC or BGCDV).");
}
if ( defined($nl->get_value('stream_year_first_lai')) ||
defined($nl->get_value('stream_year_last_lai')) ||
defined($nl->get_value('model_year_align_lai')) ||
defined($nl->get_value('lai_tintalgo' )) ||
defined($nl->get_value('stream_fldfilename_lai')) ) {
$log->fatal_error("When bgc is NOT SP none of the following can be set: stream_year_first_lai,\n" .
"stream_year_last_lai, model_year_align_lai, lai_tintalgo nor\n" .
"stream_fldfilename_lai (eg. don't use this option with BGC,CN,CNDV nor BGDCV).");
"stream_fldfilename_lai (eg. don't use this option with BGC or BGCDV).");
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cime_config/config_compsets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
<alias>I2000Clm45BgcCropQianRs</alias>
<lname>2000_DATM%QIA_CLM45%BGC-CROP_SICE_SOCN_SROF_SGLC_SWAV</lname>
</compset>
<compset>
<alias>I2000Clm50FatesQian</alias>
<lname>2000_DATM%QIA_CLM50%FATES_SICE_SOCN_MOSART_SGLC_SWAV</lname>
</compset>

<compset>
<alias>I2000Clm50BgcCruRs</alias>
Expand Down
7 changes: 3 additions & 4 deletions cime_config/testdefs/testlist_clm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2324,17 +2324,16 @@
<option name="comment" >Run a test with MEGAN on and FATES-SP</option>
</options>
</test>
<!-- Don't active this test until #1722 is fixed
<test name="SMS_Ld3" grid="f09_f09_mg17" compset="I2000Clm51FatesCruRsGs" testmods="clm/FatesColdSatPhen_prescribed">

<test name="SMS_Ld3" grid="f09_g17" compset="I2000Clm51FatesSpCruRsGs" testmods="clm/FatesColdSatPhen_prescribed">
<machines>
<machine name="cheyenne" compiler="intel" category="fates"/>
</machines>
<options>
<option name="wallclock">00:20:00</option>
<option name="comment">Test with prescribed LAI and soil-moisture with FatesSP mode, has to be at f09 and 2000</option>
<option name="comment">Test with prescribed LAI and soil moisture with FatesSP mode</option>
</options>
</test>
-->
<test name="SMS_Lm1" grid="f45_f45_mg37" compset="I2000Clm51FatesSpCruRsGs" testmods="clm/FatesColdBasic">
<machines>
<machine name="cheyenne" compiler="intel" category="fates"/>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
../FatesColdSatPhen
../prescribed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use_lai_streams = .true.
lai_tintalgo = 'lower' ! set time interpolation to use lower value, so can compare more directly to input dataset

This file was deleted.

64 changes: 64 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,68 @@
===============================================================
Tag name: ctsm5.1.dev140
Originator(s): afoster (Adrianna Foster)
Date: Tue Sep 12 09:16:37 MDT 2023
One-line Summary: add lai_streams capability for FATES

Purpose and description of changes
----------------------------------

Removed checks in clm_driver and CLMBuildNamelist.pm so that now FATES can run when use_lai_streams=.true.

I also had to modify the init in cpl/share_esmf/laiStreamMod to allocate the g_to_ig array in the lai_init method (rather than in the lai_advance method. This was required because SatellitePhenology is called in clim_initializedMod in FATES cases (here). This happens before lai_advance is ever called so at that point the g_to_ig array was not yet allocated. Moving the allocation/initialization to the lai_init method fixes this.

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.)


[ ] clm5_1

[ ] clm5_0

[ ] ctsm5_0-nwp

[ ] clm4_5

Bugs fixed or introduced
------------------------

CTSM issues fixed (include CTSM Issue #): #1722

Notes of particular relevance for developers:
---------------------------------------------

Changes to tests or testing: Added a test for lai_streams with FATES

Testing summary:
----------------
regular tests (aux_clm: https://github.com/ESCOMP/CTSM/wiki/System-Testing-Guide#pre-merge-system-testing):

cheyenne ---- OK
izumi ------- OK

fates tests: (give name of baseline if different from CTSM tagname, normally fates baselines are fates-<FATES TAG>-<CTSM TAG>)
cheyenne ---- OK
izumi ------- OK


Answer changes
--------------

Changes answers relative to baseline: None

Other details
-------------

List any externals directories updated (cime, rtm, mosart, cism, fates, etc.): fates

Pull Requests that document the changes (include PR ids): #2054
(https://github.com/ESCOMP/ctsm/pull)

===============================================================
===============================================================
Tag name: ctsm5.1.dev139
Originator(s): slevis (Samuel Levis)
Date: Fri Aug 25 16:47:45 MDT 2023
Expand Down
1 change: 1 addition & 0 deletions doc/ChangeSum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Tag Who Date Summary
============================================================================================================================
ctsm5.1.dev140 afoster 09/12/2023 add lai_streams capability for FATES
ctsm5.1.dev139 slevis 08/28/2023 Fix problems uncovered by nag -nan tests
ctsm5.1.dev138 slevis 08/25/2023 Refactor max_patch_per_col and maxsoil_patches loops
ctsm5.1.dev137 slevis 08/23/2023 Surface roughness modifications
Expand Down
11 changes: 10 additions & 1 deletion src/cpl/share_esmf/laiStreamMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ subroutine lai_init(bounds)
type(bounds_type), intent(in) :: bounds ! bounds
!
! !LOCAL VARIABLES:
integer :: i,n ! index
integer :: i,n, ig, g ! index
integer :: stream_year_first_lai ! first year in Lai stream to use
integer :: stream_year_last_lai ! last year in Lai stream to use
integer :: model_year_align_lai ! align stream_year_first_lai with
Expand Down Expand Up @@ -151,6 +151,15 @@ subroutine lai_init(bounds)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) then
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if

if ( .not. allocated(g_to_ig) )then
allocate (g_to_ig(bounds%begg:bounds%endg) )
ig = 0
do g = bounds%begg,bounds%endg
ig = ig+1
g_to_ig(g) = ig
end do
end if

end subroutine lai_init

Expand Down
8 changes: 4 additions & 4 deletions src/main/clm_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
! Specified phenology
! Done in SP mode, FATES-SP mode and also when dry-deposition is active
! ============================================================================

if (use_cn) then
! For dry-deposition need to call CLMSP so that mlaidiff is obtained
! NOTE: This is also true of FATES below
Expand Down Expand Up @@ -264,7 +264,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
end if

end if

! ==================================================================================
! Determine decomp vertical profiles
!
Expand Down Expand Up @@ -468,8 +468,8 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro

! When LAI streams are being used
! NOTE: This call needs to happen outside loops over nclumps (as streams are not threadsafe)
if ((.not. use_cn) .and. (.not. use_fates) .and. (doalb) .and. use_lai_streams) then
call lai_advance( bounds_proc )
if (doalb .and. use_lai_streams) then
call lai_advance(bounds_proc)
endif

! When crop calendar streams are being used
Expand Down
6 changes: 3 additions & 3 deletions src/main/clm_initializeMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ subroutine initialize2(ni,nj)
elseif ( use_fates_sp ) then
call interpMonthlyVeg(bounds_proc, canopystate_inst)
end if

! Determine gridcell averaged properties to send to atm
if (nsrest == nsrStartup) then
call t_startf('init_map2gc')
Expand Down Expand Up @@ -727,7 +727,6 @@ subroutine initialize2(ni,nj)
!$OMP PARALLEL DO PRIVATE (nc, bounds_clump)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)

! FATES satellite phenology mode needs to include all active and inactive patch-level soil
! filters due to the translation between the hlm pfts and the fates pfts.
! E.g. in FATES, an active PFT vector of 1, 0, 0, 0, 1, 0, 1, 0 would be mapped into
Expand All @@ -740,11 +739,12 @@ subroutine initialize2(ni,nj)
end do
!$OMP END PARALLEL DO
end if

call clm_fates%init_coldstart(water_inst%waterstatebulk_inst, &
water_inst%waterdiagnosticbulk_inst, canopystate_inst, &
soilstate_inst, soilbiogeochem_carbonflux_inst)
end if

! topo_glc_mec was allocated in initialize1, but needed to be kept around through
! initialize2 because it is used to initialize other variables; now it can be deallocated
deallocate(topo_glc_mec, fert_cft, irrig_method)
Expand Down
1 change: 1 addition & 0 deletions src/main/clm_varcon.F90
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module clm_varcon

integer, public, parameter :: fun_period = 1 ! A FUN parameter, and probably needs to be changed for testing
real(r8),public, parameter :: smallValue = 1.e-12_r8 ! A small values used by FUN
real(r8),public, parameter :: sum_to_1_tol = 1.e-13_r8 ! error tolerance

! ------------------------------------------------------------------------
! Special value flags
Expand Down
8 changes: 8 additions & 0 deletions src/main/controlMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ subroutine control_init(dtime)

end if

! Check compatibility with use_lai_streams
if (use_lai_streams) then
if ((use_fates .and. .not. use_fates_sp) .or. use_cn) then
call endrun(msg=' ERROR: cannot use LAI streams unless in SP mode (use_cn = .false. or use_fates_sp=.true.).'//&
errMsg(sourcefile, __LINE__))
end if
end if

! If nfix_timeconst is equal to the junk default value, then it was not specified
! by the user namelist and we need to assign it the correct default value. If the
! user specified it in the namelist, we leave it alone.
Expand Down
4 changes: 2 additions & 2 deletions src/main/surfrdUtilsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module surfrdUtilsMod
! !USES:
#include "shr_assert.h"
use shr_kind_mod , only : r8 => shr_kind_r8
use clm_varcon , only : sum_to_1_tol
use clm_varctl , only : iulog,use_fates
use abortutils , only : endrun
use shr_log_mod , only : errMsg => shr_log_errMsg
Expand Down Expand Up @@ -51,7 +52,6 @@ subroutine check_sums_equal_1(arr, lb, name, caller, ier, sumto)
logical :: found
integer :: nl
integer :: nindx
real(r8), parameter :: eps = 1.e-13_r8
real(r8), allocatable :: TotalSum(:)
integer :: ub ! upper bound of the first dimension of arr
!-----------------------------------------------------------------------
Expand All @@ -64,7 +64,7 @@ subroutine check_sums_equal_1(arr, lb, name, caller, ier, sumto)
found = .false.

do nl = lb, ub
if (abs(sum(arr(nl,:)) - TotalSum(nl)) > eps) then
if (abs(sum(arr(nl,:)) - TotalSum(nl)) > sum_to_1_tol) then
found = .true.
nindx = nl
exit
Expand Down
7 changes: 4 additions & 3 deletions src/utils/clmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module CLMFatesInterfaceMod
use clm_varcon , only : spval
use clm_varcon , only : denice
use clm_varcon , only : ispval
use clm_varcon , only : sum_to_1_tol
use clm_varpar , only : surfpft_lb,surfpft_ub
use clm_varpar , only : numrad
use clm_varpar , only : ivis
Expand Down Expand Up @@ -715,10 +716,10 @@ subroutine init(this, bounds_proc )
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).gt.1.0e-9)then
write(iulog,*) 'pft_area error in interfc ',s, sum(this%fates(nc)%bc_in(s)%pft_areafrac(:))-1.0_r8
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__))
endif
end if
end do !site

! Initialize site-level static quantities dictated by the HLM
Expand Down
Loading