Skip to content

Commit b8f021c

Browse files
authored
Merge pull request #2935 from rgknox/fates-init-itype
ctsm5.3.046: Initializing itype as spval for fates patches
2 parents bb7bc6c + d6aa46f commit b8f021c

9 files changed

Lines changed: 207 additions & 74 deletions

File tree

bld/CLMBuildNamelist.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,11 +4044,11 @@ sub setup_logic_dry_deposition {
40444044
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'drydep_list');
40454045
add_default($opts, $nl_flags->{'inputdata_rootdir'}, $definition, $defaults, $nl, 'dep_data_file');
40464046
}
4047-
if ( &value_is_true( $nl_flags->{'use_fates'}) && not &value_is_true( $nl_flags->{'use_fates_sp'}) ) {
4047+
if ( &value_is_true( $nl_flags->{'use_fates'}) ) {
40484048
foreach my $var ( @list ) {
40494049
if ( defined($nl->get_value($var)) ) {
4050-
$log->warning("DryDeposition $var is being set and can NOT be on when FATES is also on unless FATES-SP mode is on.\n" .
4051-
" Use the '--no-drydep' option when '-bgc fates' is activated");
4050+
$log->fatal_error("DryDeposition $var is being set and can NOT be on when FATES is also on.\n" .
4051+
" Use the '--no-drydep' option when '-bgc fates' is activated");
40524052
}
40534053
}
40544054
}
@@ -4171,8 +4171,8 @@ sub setup_logic_megan {
41714171
defined($nl->get_value('megan_factors_file')) ) {
41724172
check_megan_spec( $opts, $nl, $definition );
41734173
if ( &value_is_true( $nl_flags->{'use_fates'} ) ) {
4174-
$log->warning("MEGAN can NOT be on when FATES is also on.\n" .
4175-
" Use the '-no-megan' option when '-bgc fates' is activated");
4174+
$log->fatal_error("MEGAN can NOT be on when FATES is also on.\n" .
4175+
" Use the '-no-megan' option when '-bgc fates' is activated");
41764176
}
41774177
}
41784178
}

cime_config/testdefs/testlist_clm.xml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,24 +3779,25 @@
37793779
<option name="comment">Test with DEBUG on for FatesSP mode, NOTE: FatesSp has the largest difference in CTSM code for any FATES mode</option>
37803780
</options>
37813781
</test>
3782-
<test name="SMS_D" grid="1x1_brazil" compset="I2000Clm60FatesSpCruRsGs" testmods="clm/FatesColdDryDepSatPhen">
3783-
<machines>
3784-
<machine name="derecho" compiler="gnu" category="aux_clm"/>
3785-
</machines>
3786-
<options>
3787-
<option name="wallclock">00:20:00</option>
3788-
<option name="comment">Run a test with dry deposition on and FATES-SP</option>
3789-
</options>
3790-
</test>
3791-
<test name="SMS_D" grid="1x1_brazil" compset="I2000Clm60FatesSpCruRsGs" testmods="clm/FatesColdMeganSatPhen">
3792-
<machines>
3793-
<machine name="derecho" compiler="gnu" category="aux_clm"/>
3794-
</machines>
3795-
<options>
3796-
<option name="wallclock">00:20:00</option>
3797-
<option name="comment">Run a test with MEGAN on and FATES-SP</option>
3798-
</options>
3799-
</test>
3782+
<!-- DISABLING UNTIL COMPATIBLE (RGK 051925) https://github.com/ESCOMP/CTSM/issues/1784
3783+
<test name="SMS_D" grid="1x1_brazil" compset="I2000Clm60FatesSpCruRsGs" testmods="clm/FatesColdDryDepSatPhen">
3784+
<machines>
3785+
<machine name="derecho" compiler="gnu" category="aux_clm"/>
3786+
</machines>
3787+
<options>
3788+
<option name="wallclock">00:20:00</option>
3789+
<option name="comment">Run a test with dry deposition on and FATES-SP</option>
3790+
</options>
3791+
</test>
3792+
<test name="SMS_D" grid="1x1_brazil" compset="I2000Clm60FatesSpCruRsGs" testmods="clm/FatesColdMeganSatPhen">
3793+
<machines>
3794+
<machine name="derecho" compiler="gnu" category="aux_clm"/>
3795+
</machines>
3796+
<options>
3797+
<option name="wallclock">00:20:00</option>
3798+
<option name="comment">Run a test with MEGAN on and FATES-SP</option>
3799+
</options>
3800+
</test> -->
38003801

38013802
<test name="SMS_D_Ld3" grid="f09_g17" compset="I2000Clm60FatesSpCruRsGs" testmods="clm/FatesColdSatPhen_prescribed">
38023803
<machines>

doc/ChangeLog

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,99 @@
11
===============================================================
2+
Tag name: ctsm5.3.046
3+
Originator(s): rgknox (Ryan Knox)
4+
Date: Mon 26 May 2025 02:45:52 AM MDT
5+
One-line Summary: For FATES set itype to ispval and a few unused variables to nan to help prevent future problems
6+
7+
Purpose and description of changes
8+
----------------------------------
9+
10+
11+
On FATES patches, there should be no notion of pft associated with the patch, and therefore patch%itype should always be invalid.
12+
Even for FATES-SP, the patch should be associated with the FATES pft, which is not associated with itype. In this set of changes,
13+
itype is set to spval on fates patches. This will help prevent bugs in the future, because its use in a fates context should trigger
14+
errors, particularly in debug mode.
15+
16+
When FATES with itype tset o ispval which when used in DEBUG mode will show up as a bounds overflow.
17+
For example in issue 2932, where the use of Meier 2022 was turned on in FATES and shouldn't have been.
18+
19+
For FATES also set the fields downreg, leafn, froot, and croot t NaN, so when used in DEBUG mode their use will result in a floting
20+
point exception.
21+
22+
23+
Significant changes to scientifically-supported configurations
24+
--------------------------------------------------------------
25+
26+
Does this tag change answers significantly for any of the following physics configurations?
27+
(Details of any changes will be given in the "Answer changes" section below.)
28+
29+
[Put an [X] in the box for any configuration with significant answer changes.]
30+
31+
[ ] clm6_0
32+
33+
[ ] clm5_0
34+
35+
[ ] ctsm5_0-nwp
36+
37+
[ ] clm4_5
38+
39+
40+
Bugs fixed
41+
----------
42+
43+
List of CTSM issues fixed (include CTSM Issue # and description) [one per line]:
44+
Fixed #2933 -- setting patch%itype to invalid for FATES patches
45+
46+
Notes of particular relevance for users
47+
---------------------------------------
48+
49+
Changes to CTSM's user interface (e.g., new/renamed XML or namelist variables):
50+
Dissallow drydep or MEGAN for all FATES types including FatesSp and die with
51+
a fatal_error, rather than a warning
52+
53+
Notes of particular relevance for developers:
54+
---------------------------------------------
55+
56+
Caveats for developers (e.g., code that is duplicated that requires double maintenance):
57+
Unfrtunately setting itype doesn't fix all possible problems with
58+
See discussin #2149
59+
60+
Changes to tests or testing:
61+
Disable FatesSp drydep and MEGAN tests
62+
63+
Testing summary: regular fates
64+
----------------
65+
[PASS means all tests PASS; OK means tests PASS other than expected fails.]
66+
67+
build-namelist tests (if CLMBuildNamelist.pm has changed):
68+
69+
derecho - OK
70+
71+
python testing (if python code has changed; see instructions in python/README.md; document testing done):
72+
73+
derecho - PASS
74+
75+
regular tests (aux_clm: https://github.com/ESCOMP/CTSM/wiki/System-Testing-Guide#pre-merge-system-testing):
76+
77+
derecho ----- OK
78+
izumi ------- OK
79+
80+
If the tag used for baseline comparisons was NOT the previous tag, note that here:
81+
82+
83+
Answer changes
84+
--------------
85+
86+
Changes answers relative to baseline: No bit-fr-bit
87+
88+
Other details
89+
-------------
90+
91+
Pull Requests that document the changes (include PR ids):
92+
(https://github.com/ESCOMP/ctsm/pull)
93+
https://github.com/ESCOMP/CTSM/pull/2935
94+
95+
===============================================================
96+
===============================================================
297
Tag name: ctsm5.3.045
398
Originator(s): glemieux (Gregory Lemieux, LBNL, [email protected])
499
Date: Tue May 20 11:56:15 MDT 2025

doc/ChangeSum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Tag Who Date Summary
22
============================================================================================================================
3+
ctsm5.3.046 rgknox 05/26/2025 For FATES set itype to ispval and a few unused variables to nan to help prevent future problems
34
ctsm5.3.045 glemieux 05/20/2025 FATES default parameter update for API 40
45
ctsm5.3.044 slevis 05/14/2025 Introduce time-evolving LEAFCN_TARGET as function of leafcn param
56
ctsm5.3.043 slevis 05/09/2025 Merge b4b-dev

src/biogeochem/SatellitePhenologyMod.F90

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module SatellitePhenologyMod
1717
use perf_mod , only : t_startf, t_stopf
1818
use spmdMod , only : masterproc, mpicom, iam
1919
use laiStreamMod , only : lai_init, lai_advance, lai_interp
20+
use clm_varctl , only : use_fates
2021
use ncdio_pio
2122
!
2223
! !PUBLIC TYPES:
@@ -170,7 +171,7 @@ subroutine UpdateSatellitePhenologyCanopy(bounds, num_filter, filter, &
170171
use WaterDiagnosticBulkType , only : waterdiagnosticbulk_type
171172
use CanopyStateType , only : canopystate_type
172173
use PatchType , only : patch
173-
use clm_varctl , only : use_fates
174+
174175

175176
!
176177
! !ARGUMENTS:
@@ -415,7 +416,9 @@ subroutine readMonthlyVegetation (bounds, fveg, months, canopystate_inst)
415416
use clm_time_manager , only : get_nstep
416417
use CanopyStateType , only : canopystate_type
417418
use PatchType , only : patch
419+
use ColumnType , only : col
418420
use clm_varcon , only : grlnd
421+
use clm_varpar , only : surfpft_lb,surfpft_ub
419422
use netcdf
420423
!
421424
! !ARGUMENTS:
@@ -428,6 +431,7 @@ subroutine readMonthlyVegetation (bounds, fveg, months, canopystate_inst)
428431
character(len=256) :: locfn ! local file name
429432
type(file_desc_t) :: ncid ! netcdf id
430433
integer :: g,n,k,l,m,p,ni,nj,ns ! indices
434+
integer :: c,ft ! indices
431435
integer :: dimid,varid ! input netCDF id's
432436
integer :: ntim ! number of input data time samples
433437
integer :: nlon_i ! number of input data longitudes
@@ -485,25 +489,40 @@ subroutine readMonthlyVegetation (bounds, fveg, months, canopystate_inst)
485489
! Assign lai/sai/hgtt/hgtb to the top [maxsoil_patches] patches
486490
! as determined in subroutine surfrd
487491

488-
do p = bounds%begp,bounds%endp
489-
g =patch%gridcell(p)
490-
if (patch%itype(p) /= noveg) then ! vegetated pft
491-
do l = 0, maxveg
492-
if (l == patch%itype(p)) then
493-
mlai2t(p,k) = mlai(g,l)
494-
msai2t(p,k) = msai(g,l)
495-
mhvt2t(p,k) = mhgtt(g,l)
496-
mhvb2t(p,k) = mhgtb(g,l)
497-
end if
498-
end do
499-
else ! non-vegetated pft
500-
mlai2t(p,k) = 0._r8
501-
msai2t(p,k) = 0._r8
502-
mhvt2t(p,k) = 0._r8
503-
mhvb2t(p,k) = 0._r8
504-
end if
505-
end do ! end of loop over patches
506-
492+
if_fates: if(use_fates)then
493+
do c = bounds%begc,bounds%endc
494+
if(col%is_fates(c))then
495+
do ft = surfpft_lb,surfpft_ub
496+
p = ft + col%patchi(c)
497+
g = patch%gridcell(p)
498+
mlai2t(p,k) = mlai(g,ft)
499+
msai2t(p,k) = msai(g,ft)
500+
mhvt2t(p,k) = mhgtt(g,ft)
501+
mhvb2t(p,k) = mhgtb(g,ft)
502+
end do
503+
end if
504+
end do
505+
else
506+
do p = bounds%begp,bounds%endp
507+
g = patch%gridcell(p)
508+
if (patch%itype(p) /= noveg ) then ! vegetated pft
509+
do l = 0, maxveg
510+
if (l == patch%itype(p)) then
511+
mlai2t(p,k) = mlai(g,l)
512+
msai2t(p,k) = msai(g,l)
513+
mhvt2t(p,k) = mhgtt(g,l)
514+
mhvb2t(p,k) = mhgtb(g,l)
515+
end if
516+
end do
517+
else ! non-vegetated pft
518+
mlai2t(p,k) = 0._r8
519+
msai2t(p,k) = 0._r8
520+
mhvt2t(p,k) = 0._r8
521+
mhvb2t(p,k) = 0._r8
522+
end if
523+
end do ! end of loop over patches
524+
end if if_fates
525+
507526
end do ! end of loop over months
508527

509528
call ncd_pio_closefile(ncid)

src/biogeophys/SurfaceAlbedoMod.F90

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -902,23 +902,6 @@ subroutine SurfaceAlbedo(bounds,nc, &
902902
end if
903903
end do
904904

905-
! Weight reflectance/transmittance by lai and sai
906-
! Only perform on vegetated patches where coszen > 0
907-
908-
do fp = 1,num_vegsol
909-
p = filter_vegsol(fp)
910-
wl(p) = elai(p) / max( elai(p)+esai(p), mpe )
911-
ws(p) = esai(p) / max( elai(p)+esai(p), mpe )
912-
end do
913-
914-
do ib = 1, numrad
915-
do fp = 1,num_vegsol
916-
p = filter_vegsol(fp)
917-
rho(p,ib) = max( rhol(patch%itype(p),ib)*wl(p) + rhos(patch%itype(p),ib)*ws(p), mpe )
918-
tau(p,ib) = max( taul(patch%itype(p),ib)*wl(p) + taus(patch%itype(p),ib)*ws(p), mpe )
919-
end do
920-
end do
921-
922905
! Diagnose number of canopy layers for radiative transfer, in increments of dincmax.
923906
! Add to number of layers so long as cumulative leaf+stem area does not exceed total
924907
! leaf+stem area. Then add any remaining leaf+stem area to next layer and exit the loop.
@@ -1086,7 +1069,24 @@ subroutine SurfaceAlbedo(bounds,nc, &
10861069
call clm_fates%wrap_canopy_radiation(bounds, nc, fcansno(bounds%begp:bounds%endp), surfalb_inst)
10871070

10881071
else
1089-
1072+
1073+
! Weight reflectance/transmittance by lai and sai
1074+
! Only perform on vegetated patches where coszen > 0
1075+
1076+
do fp = 1,num_vegsol
1077+
p = filter_vegsol(fp)
1078+
wl(p) = elai(p) / max( elai(p)+esai(p), mpe )
1079+
ws(p) = esai(p) / max( elai(p)+esai(p), mpe )
1080+
end do
1081+
1082+
do ib = 1, numrad
1083+
do fp = 1,num_vegsol
1084+
p = filter_vegsol(fp)
1085+
rho(p,ib) = max( rhol(patch%itype(p),ib)*wl(p) + rhos(patch%itype(p),ib)*ws(p), mpe )
1086+
tau(p,ib) = max( taul(patch%itype(p),ib)*wl(p) + taus(patch%itype(p),ib)*ws(p), mpe )
1087+
end do
1088+
end do
1089+
10901090
call TwoStream (bounds, filter_vegsol, num_vegsol, &
10911091
coszen_patch(bounds%begp:bounds%endp), &
10921092
rho(bounds%begp:bounds%endp, :), &

src/main/clm_driver.F90

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module clm_driver
1818
use clm_time_manager , only : get_nstep, is_beg_curr_day, is_beg_curr_year
1919
use clm_time_manager , only : get_prev_date, is_first_step
2020
use clm_varpar , only : nlevsno, nlevgrnd
21+
use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=)
2122
use clm_varorb , only : obliqr
2223
use spmdMod , only : masterproc, mpicom
2324
use decompMod , only : get_proc_clumps, get_clump_bounds, get_proc_bounds, bounds_type
@@ -727,16 +728,30 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate, ro
727728
! bugs.
728729
allocate(downreg_patch(bounds_clump%begp:bounds_clump%endp))
729730
allocate(leafn_patch(bounds_clump%begp:bounds_clump%endp))
730-
downreg_patch = bgc_vegetation_inst%get_downreg_patch(bounds_clump)
731-
leafn_patch = bgc_vegetation_inst%get_leafn_patch(bounds_clump)
732-
733731
allocate(froot_carbon(bounds_clump%begp:bounds_clump%endp))
734732
allocate(croot_carbon(bounds_clump%begp:bounds_clump%endp))
735-
froot_carbon = bgc_vegetation_inst%get_froot_carbon_patch( &
736-
bounds_clump, canopystate_inst%tlai_patch(bounds_clump%begp:bounds_clump%endp))
737-
croot_carbon = bgc_vegetation_inst%get_croot_carbon_patch( &
738-
bounds_clump, canopystate_inst%tlai_patch(bounds_clump%begp:bounds_clump%endp))
739733

734+
! The get functions for these four patch arrays are relevant only
735+
! for native cn vegetation. More importantly, they utilize patch%itype(p)
736+
! which is invalid for fates patches and cannot be accessed without failure
737+
! These arrays must be passed as arguments, so we clearly fill them here
738+
! with unusuable special values when fates is active, and meaningful values
739+
! when fates is not active.
740+
741+
if(use_fates)then
742+
downreg_patch(:) = nan
743+
leafn_patch(:) = nan
744+
froot_carbon(:) = nan
745+
croot_carbon(:) = nan
746+
else
747+
downreg_patch = bgc_vegetation_inst%get_downreg_patch(bounds_clump)
748+
leafn_patch = bgc_vegetation_inst%get_leafn_patch(bounds_clump)
749+
froot_carbon = bgc_vegetation_inst%get_froot_carbon_patch( &
750+
bounds_clump, canopystate_inst%tlai_patch(bounds_clump%begp:bounds_clump%endp))
751+
croot_carbon = bgc_vegetation_inst%get_croot_carbon_patch( &
752+
bounds_clump, canopystate_inst%tlai_patch(bounds_clump%begp:bounds_clump%endp))
753+
end if
754+
740755
call CanopyFluxes(bounds_clump, &
741756
filter(nc)%num_exposedvegp, filter(nc)%exposedvegp, &
742757
clm_fates,nc, &

src/main/subgridWeightsMod.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ subroutine init_subgrid_weights_mod(bounds)
193193
avgflag='A', long_name='% of each landunit on grid cell', &
194194
ptr_lnd=subgrid_weights_diagnostics%pct_landunit)
195195

196-
if(.not.use_fates.or.use_fates_sp) then
196+
if(.not.use_fates) then
197197
call hist_addfld2d (fname='PCT_NAT_PFT', units='%', type2d='natpft', &
198198
avgflag='A', long_name='% of each PFT on the natural vegetation (i.e., soil) landunit', &
199199
ptr_lnd=subgrid_weights_diagnostics%pct_nat_pft)
@@ -770,7 +770,7 @@ subroutine set_subgrid_diagnostic_fields(bounds)
770770
! Note: (SPM, 10-20-15): If this isn't set then debug mode with intel and
771771
! yellowstone will fail when trying to write pct_nat_pft since it contains
772772
! all NaN's.
773-
call set_pct_pft_diagnostics(bounds)
773+
if(.not.use_fates) call set_pct_pft_diagnostics(bounds)
774774

775775
call set_pct_glc_mec_diagnostics(bounds)
776776

0 commit comments

Comments
 (0)