Skip to content

Commit

Permalink
Add CROPPHASE_TIME_*_PERHARV outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Feb 15, 2025
1 parent 327451d commit 6c30de8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cime_config/testdefs/testmods_dirs/clm/crop/user_nl_clm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hist_fincl2 += 'DYN_COL_SOIL_ADJUSTMENTS_C'
! Note that, under normal circumstances, these should only be saved annually.
! That's needed for the mxsowings and mxharvests axes to make sense.
! However, for testing purposes, it makes sense to save more frequently.
hist_fincl3 = 'SDATES', 'SDATES_PERHARV', 'SYEARS_PERHARV', 'HDATES', 'GRAINC_TO_FOOD_PERHARV', 'GRAINC_TO_FOOD_ANN', 'GRAINN_TO_FOOD_PERHARV', 'GRAINN_TO_FOOD_ANN', 'GRAINC_TO_SEED_PERHARV', 'GRAINC_TO_SEED_ANN', 'GRAINN_TO_SEED_PERHARV', 'GRAINN_TO_SEED_ANN', 'HDATES', 'GDDHARV_PERHARV', 'GDDACCUM_PERHARV', 'HUI_PERHARV', 'SOWING_REASON_PERHARV', 'HARVEST_REASON_PERHARV', 'SWINDOW_STARTS', 'SWINDOW_ENDS', 'GDD20_BASELINE', 'GDD20_SEASON_START', 'GDD20_SEASON_END', 'MAXLAIGRAINFILL', 'MAXLAIGRAINFILL_PERHARV'
hist_fincl3 = 'SDATES', 'SDATES_PERHARV', 'SYEARS_PERHARV', 'HDATES', 'GRAINC_TO_FOOD_PERHARV', 'GRAINC_TO_FOOD_ANN', 'GRAINN_TO_FOOD_PERHARV', 'GRAINN_TO_FOOD_ANN', 'GRAINC_TO_SEED_PERHARV', 'GRAINC_TO_SEED_ANN', 'GRAINN_TO_SEED_PERHARV', 'GRAINN_TO_SEED_ANN', 'HDATES', 'GDDHARV_PERHARV', 'GDDACCUM_PERHARV', 'HUI_PERHARV', 'SOWING_REASON_PERHARV', 'HARVEST_REASON_PERHARV', 'SWINDOW_STARTS', 'SWINDOW_ENDS', 'GDD20_BASELINE', 'GDD20_SEASON_START', 'GDD20_SEASON_END', 'MAXLAIGRAINFILL', 'MAXLAIGRAINFILL_PERHARV', 'CROPPHASE_TIME_PRE_PERHARV', 'CROPPHASE_TIME_VEG_PERHARV', 'CROPPHASE_TIME_REP_PERHARV'
hist_nhtfrq = -24,-8,-24
hist_mfilt = 1,1,1
hist_type1d_pertape(3) = 'PFTS'
Expand Down
21 changes: 21 additions & 0 deletions src/biogeochem/CNPhenologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,9 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
crop_inst%hui_thisyr_patch(p,s) = -1._r8
crop_inst%sowing_reason_perharv_patch(p,s) = -1._r8
crop_inst%maxlai_triggered_grainfill_perharv_patch(p,s) = 0._r8
crop_inst%cropphase_time_pre_perharv_patch(p,s) = -1._r8
crop_inst%cropphase_time_veg_perharv_patch(p,s) = -1._r8
crop_inst%cropphase_time_rep_perharv_patch(p,s) = -1._r8
crop_inst%harvest_reason_thisyr_patch(p,s) = -1._r8
do k = repr_grain_min, repr_grain_max
cnveg_carbonflux_inst%repr_grainc_to_food_perharv_patch(p,s,k) = 0._r8
Expand Down Expand Up @@ -2556,6 +2559,12 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
crop_inst%maxlai_triggered_grainfill_ann_patch(p) + 1._r8
crop_inst%maxlai_triggered_grainfill_perharv_patch(p, harvest_count(p)) = 1._r8
end if
crop_inst%cropphase_time_pre_perharv_patch(p, harvest_count(p)) = &
crop_inst%cropphase_time_pre_patch(p)
crop_inst%cropphase_time_veg_perharv_patch(p, harvest_count(p)) = &
crop_inst%cropphase_time_veg_patch(p)
crop_inst%cropphase_time_rep_perharv_patch(p, harvest_count(p)) = &
crop_inst%cropphase_time_rep_patch(p)
endif

croplive(p) = .false. ! no re-entry in greater if-block
Expand Down Expand Up @@ -2627,6 +2636,15 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
crop_inst%sown_in_this_window(p) = .false.
end if

! Update time spent in crop phase
if (cphase(p) == cphase_planted) then
crop_inst%cropphase_time_pre_patch = crop_inst%cropphase_time_pre_patch + fracday
else if (cphase(p) == cphase_leafemerge) then
crop_inst%cropphase_time_veg_patch = crop_inst%cropphase_time_veg_patch + fracday
else if (cphase(p) == cphase_grainfill) then
crop_inst%cropphase_time_rep_patch = crop_inst%cropphase_time_rep_patch + fracday
end if

end do ! prognostic crops loop

end associate
Expand Down Expand Up @@ -2848,6 +2866,9 @@ subroutine PlantCrop(p, leafcn_in, jday, kyr, do_plant_normal, &
harvdate(p) = NOT_Harvested
sowing_count(p) = sowing_count(p) + 1
crop_inst%maxlai_triggered_grainfill_patch(p) = .false.
crop_inst%cropphase_time_pre_patch(p) = 0._r8
crop_inst%cropphase_time_veg_patch(p) = 0._r8
crop_inst%cropphase_time_rep_patch(p) = 0._r8

crop_inst%sdates_thisyr_patch(p,sowing_count(p)) = real(jday, r8)

Expand Down
55 changes: 55 additions & 0 deletions src/biogeochem/CropType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ module CropType
real(r8), pointer :: maxlai_triggered_grainfill_ann_patch (:) ! Number of times in calendar year that max LAI triggered grain fill
real(r8), pointer :: maxlai_triggered_grainfill_perharv_patch (:,:) ! Whether a given season (indexed on harvest) had max LAI trigger grain fill

! SSR 2025-02-14: Temporary diagnostic variables used in reparameterizing crops for CLM6
real(r8), pointer :: cropphase_time_pre_patch (:) ! Time (days) spent in cphase_planted ("pre-emergence" phase) for the current season
real(r8), pointer :: cropphase_time_veg_patch (:) ! Time (days) spent in cphase_leafemerge ("vegetative" phase) for the current season
real(r8), pointer :: cropphase_time_rep_patch (:) ! Time (days) spent in cphase_grainfill ("reproductive" phase) for the current season
real(r8), pointer :: cropphase_time_pre_perharv_patch (:,:) ! Time (days) spent in cphase_planted ("pre-emergence" phase) for each season in this calendar year
real(r8), pointer :: cropphase_time_veg_perharv_patch (:,:) ! Time (days) spent in cphase_leafemerge ("vegetative" phase) for each season in this calendar year
real(r8), pointer :: cropphase_time_rep_perharv_patch (:,:) ! Time (days) spent in cphase_grainfill ("reproductive" phase) for each season in this calendar year

contains
! Public routines
procedure, public :: Init ! Initialize the crop type
Expand Down Expand Up @@ -263,6 +271,12 @@ subroutine InitAllocate(this, bounds)
allocate(this%maxlai_triggered_grainfill_patch(begp:endp)) ; this%maxlai_triggered_grainfill_patch(:) = .false.
allocate(this%maxlai_triggered_grainfill_ann_patch(begp:endp)) ; this%maxlai_triggered_grainfill_ann_patch(:) = spval
allocate(this%maxlai_triggered_grainfill_perharv_patch(begp:endp,1:mxharvests)) ; this%maxlai_triggered_grainfill_perharv_patch(:,:) = spval
allocate(this%cropphase_time_pre_patch(begp:endp)) ; this%cropphase_time_pre_patch(:) = spval
allocate(this%cropphase_time_veg_patch(begp:endp)) ; this%cropphase_time_veg_patch(:) = spval
allocate(this%cropphase_time_rep_patch(begp:endp)) ; this%cropphase_time_rep_patch(:) = spval
allocate(this%cropphase_time_pre_perharv_patch(begp:endp,1:mxharvests)) ; this%cropphase_time_pre_perharv_patch(:,:) = spval
allocate(this%cropphase_time_veg_perharv_patch(begp:endp,1:mxharvests)) ; this%cropphase_time_veg_perharv_patch(:,:) = spval
allocate(this%cropphase_time_rep_perharv_patch(begp:endp,1:mxharvests)) ; this%cropphase_time_rep_perharv_patch(:,:) = spval

end subroutine InitAllocate

Expand Down Expand Up @@ -395,6 +409,19 @@ subroutine InitHistory(this, bounds)
avgflag='I', long_name='Whether a given season (indexed on harvest) had max LAI trigger grain fill', &
ptr_patch=this%maxlai_triggered_grainfill_perharv_patch, default='inactive')

this%cropphase_time_pre_perharv_patch(begp:endp,:) = spval
call hist_addfld2d (fname='CROPPHASE_TIME_PRE_PERHARV', units='days', type2d='mxharvests', &
avgflag='I', long_name='Time spent in cphase_planted ("pre-emergence" phase) for each harvest', &
ptr_patch=this%cropphase_time_pre_perharv_patch, default='inactive')
this%cropphase_time_veg_perharv_patch(begp:endp,:) = spval
call hist_addfld2d (fname='CROPPHASE_TIME_VEG_PERHARV', units='days', type2d='mxharvests', &
avgflag='I', long_name='Time spent in cphase_leafemerge ("vegetative" phase) for each harvest', &
ptr_patch=this%cropphase_time_veg_perharv_patch, default='inactive')
this%cropphase_time_rep_perharv_patch(begp:endp,:) = spval
call hist_addfld2d (fname='CROPPHASE_TIME_REP_PERHARV', units='days', type2d='mxharvests', &
avgflag='I', long_name='Time spent in cphase_grainfill ("reproductive" phase) for each harvest', &
ptr_patch=this%cropphase_time_rep_perharv_patch, default='inactive')

end subroutine InitHistory

subroutine InitCold(this, bounds)
Expand Down Expand Up @@ -706,6 +733,19 @@ subroutine Restart(this, bounds, ncid, cnveg_state_inst, flag)
units='none', &
interpinic_flag='interp', readvar=readvar, data=this%maxlai_triggered_grainfill_ann_patch)

call restartvar(ncid=ncid, flag=flag, varname='cropphase_time_pre_patch',xtype=ncd_double, &
dim1name='pft', long_name='Time spent in cphase_planted ("pre-emergence" phase) for the current season', &
units='days', &
interpinic_flag='interp', readvar=readvar, data=this%cropphase_time_pre_patch)
call restartvar(ncid=ncid, flag=flag, varname='cropphase_time_veg_patch',xtype=ncd_double, &
dim1name='pft', long_name='Time spent in cphase_leafemerge ("vegetative" phase) for the current season', &
units='days', &
interpinic_flag='interp', readvar=readvar, data=this%cropphase_time_veg_patch)
call restartvar(ncid=ncid, flag=flag, varname='cropphase_time_rep_patch',xtype=ncd_double, &
dim1name='pft', long_name='Time spent in cphase_grainfill ("reproductive" phase) for the current season', &
units='days', &
interpinic_flag='interp', readvar=readvar, data=this%cropphase_time_rep_patch)

! Read or write variable(s) with mxsowings dimension
! BACKWARDS_COMPATIBILITY(wjs/ssr, 2022-02-02) See note in CallRestartvarDimOK()
if (CallRestartvarDimOK(ncid, flag, 'mxsowings')) then
Expand Down Expand Up @@ -788,6 +828,21 @@ subroutine Restart(this, bounds, ncid, cnveg_state_inst, flag)
long_name='Whether a given season (indexed on harvest) had max LAI trigger grain fill', units='unitless', &
scale_by_thickness=.false., &
interpinic_flag='interp', readvar=readvar, data=this%maxlai_triggered_grainfill_perharv_patch)
call restartvar(ncid=ncid, flag=flag, varname='cropphase_time_pre_perharv_patch', xtype=ncd_double, &
dim1name='pft', dim2name='mxharvests', switchdim=.true., &
long_name='Time spent in cphase_planted ("pre-emergence" phase) for each harvest', units='days', &
scale_by_thickness=.false., &
interpinic_flag='interp', readvar=readvar, data=this%cropphase_time_pre_perharv_patch)
call restartvar(ncid=ncid, flag=flag, varname='cropphase_time_veg_perharv_patch', xtype=ncd_double, &
dim1name='pft', dim2name='mxharvests', switchdim=.true., &
long_name='Time spent in cphase_leafemerge ("vegetative" phase) for each harvest', units='days', &
scale_by_thickness=.false., &
interpinic_flag='interp', readvar=readvar, data=this%cropphase_time_veg_perharv_patch)
call restartvar(ncid=ncid, flag=flag, varname='cropphase_time_rep_perharv_patch', xtype=ncd_double, &
dim1name='pft', dim2name='mxharvests', switchdim=.true., &
long_name='Time spent in cphase_grainfill ("reproductive" phase) for each harvest', units='days', &
scale_by_thickness=.false., &
interpinic_flag='interp', readvar=readvar, data=this%cropphase_time_rep_perharv_patch)

! Fill variable(s) derived from read-in variable(s)
if (flag == 'read') then
Expand Down

0 comments on commit 6c30de8

Please sign in to comment.