Skip to content

Commit

Permalink
Prevent crops from being sown twice in one sowing window.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Sep 19, 2023
1 parent 4e36dda commit e22260b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/biogeochem/CNPhenologyMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
use clm_time_manager , only : get_prev_calday, get_curr_days_per_year, is_beg_curr_year
use clm_time_manager , only : get_average_days_per_year
use clm_time_manager , only : get_prev_date
use clm_time_manager , only : is_doy_in_interval
use clm_time_manager , only : is_doy_in_interval, is_end_curr_day
use pftconMod , only : ntmp_corn, nswheat, nwwheat, ntmp_soybean
use pftconMod , only : nirrig_tmp_corn, nirrig_swheat, nirrig_wwheat, nirrig_tmp_soybean
use pftconMod , only : ntrp_corn, nsugarcane, ntrp_soybean, ncotton, nrice
Expand Down Expand Up @@ -1962,6 +1962,9 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
sowing_window_enddate = maxplantjday(ivt(p),h)
end if
is_in_sowing_window = is_doy_in_interval(sowing_window_startdate, sowing_window_enddate, jday)
if (crop_inst%sown_in_this_window .and. .not. is_in_sowing_window) then
crop_inst%sown_in_this_window = .false.
end if
is_end_sowing_window = jday == sowing_window_enddate
!
! Save these diagnostic variables only on the first day of the window to ensure that windows spanning the new year aren't double-counted.
Expand Down Expand Up @@ -2199,8 +2202,8 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &

! If generate_crop_gdds and this patch has prescribed sowing inputs
else if (generate_crop_gdds .and. crop_inst%rx_swindow_starts_thisyr_patch(p,1) .gt. 0) then
if (next_rx_swindow_start(p) >= 0) then
! Harvest the day before the start of the next sowing window this year.
if (next_rx_swindow_start(p) >= 0 .and. is_end_curr_day()) then
! Harvest the timestep before the start of the next sowing window this year.
do_harvest = jday == next_rx_swindow_start(p) - 1

! ... unless that will lead to growing season length 365 (or 366,
Expand Down Expand Up @@ -2229,7 +2232,7 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
! In order to avoid this, you'd have to read this year's AND next year's prescribed
! sowing window start dates.
if (crop_inst%rx_swindow_starts_thisyr_patch(p,1) == 1) then
do_harvest = jday == dayspyr
do_harvest = jday == dayspyr .and. is_end_curr_day()
end if

if (do_harvest) then
Expand Down Expand Up @@ -2257,7 +2260,8 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &
if (use_cropcal_rx_swindows) then
will_plant_prescribed_tomorrow = (jday == next_rx_swindow_start(p) - 1) .or. &
(crop_inst%sdates_thisyr_patch(p,1) == 1 .and. &
jday == dayspyr)
jday == dayspyr .and.
is_end_curr_day())
else
will_plant_prescribed_tomorrow = .false.
end if
Expand Down Expand Up @@ -2323,6 +2327,12 @@ subroutine CropPhenology(num_pcropp, filter_pcropp , &

croplive(p) = .false. ! no re-entry in greater if-block
cphase(p) = cphase_harvest

! Avoid situation where a crop could be stuck with sown_in_this_window true when moving from one sowing window to another with no days in between.
if (harvest_reason == HARVEST_REASON_SOWTOMORROW .or. harvest_reason == HARVEST_REASON_IDOPTOMORROW) then
crop_inst%sown_in_this_window = .false.
end if

if (tlai(p) > 0._r8) then ! plant had emerged before harvest
offset_flag(p) = 1._r8
offset_counter(p) = dt
Expand Down Expand Up @@ -2600,6 +2610,7 @@ subroutine PlantCrop(p, leafcn_in, jday, kyr, do_plant_normal, &
! impose limit on growing season length needed
! for crop maturity - for cold weather constraints
croplive(p) = .true.
crop_inst%sown_in_this_window = .true.
idop(p) = jday
iyop(p) = kyr
harvdate(p) = NOT_Harvested
Expand Down
6 changes: 6 additions & 0 deletions src/biogeochem/CropType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module CropType
character(len=20) :: baset_mapping
real(r8) :: baset_latvary_intercept
real(r8) :: baset_latvary_slope
logical , pointer :: sown_in_this_window (:) ! patch flag. True if the crop has already been sown during the current sowing window. False otherwise or if not in a sowing window.
integer , pointer :: next_rx_swindow_start_patch (:) ! start of prescribed sowing window for the next growing season this year
integer , pointer :: next_rx_swindow_end_patch (:) ! end of prescribed sowing window for the next growing season this year
integer , pointer :: rx_swindow_starts_thisyr_patch(:,:) ! all prescribed sowing window start dates for this patch this year (day of year) [patch, mxsowings]
Expand Down Expand Up @@ -231,6 +232,7 @@ subroutine InitAllocate(this, bounds)
allocate(this%cphase_patch (begp:endp)) ; this%cphase_patch (:) = cphase_not_planted
allocate(this%sowing_reason_patch (begp:endp)) ; this%sowing_reason_patch (:) = -1
allocate(this%latbaset_patch (begp:endp)) ; this%latbaset_patch (:) = spval
allocate(this%sown_in_this_window(begp:endp)) ; this%sown_in_this_window(:) = .false.
allocate(this%next_rx_swindow_start_patch(begp:endp)) ; this%next_rx_swindow_start_patch(:) = -1
allocate(this%next_rx_swindow_end_patch (begp:endp)) ; this%next_rx_swindow_end_patch (:) = -1
allocate(this%rx_swindow_starts_thisyr_patch(begp:endp,1:mxsowings)); this%rx_swindow_starts_thisyr_patch(:,:) = -1
Expand Down Expand Up @@ -627,6 +629,10 @@ subroutine Restart(this, bounds, ncid, cnveg_state_inst, flag)
dim1name='pft', long_name='sowing reason for this patch', &
units='none', &
interpinic_flag='interp', readvar=readvar, data=this%sowing_reason_patch)
call restartvar(ncid=ncid, flag=flag, varname='sown_in_this_window', xtype=ncd_log, &
dim1name='pft', &
long_name='whether this patch was sown already during the current sowing window', &
interpinic_flag='interp', readvar=readvar, data=this%sown_in_this_window)

! Read or write variable(s) with mxsowings dimension
! BACKWARDS_COMPATIBILITY(wjs/ssr, 2022-02-02) See note in CallRestartvarDimOK()
Expand Down

0 comments on commit e22260b

Please sign in to comment.