Clean up fertilization logic
- Dominant language
- Fortran
- Stars
- 352
- Forks
- 361
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
**Comment from 2016-10-15, but I think it's still relevant**
Looking through the clm code (CNPhenologyMod) to try to understand how onset_counter works with fertilizer:
It looks like, for all specific (non-generic) crops, the only place onset_counter is set / updated is in CropPhenology (other than its initialization to 0):
onset_counter(p) = onset_counter(p) - dt
! enter phase 2 onset for one time step:
! transfer seed carbon to leaf emergence
if (leafout(p) >= huileaf(p) .and. hui(p) < huigrain(p) .and. idpp < mxmat(ivt(p))) then
if (abs(onset_counter(p)) > 1.e-6_r8) then
onset_flag(p) = 1._r8
onset_counter(p) = dt
fert_counter(p) = ndays_on * secspday
fert(p) = fertnitro(ivt(p)) * 1000._r8 / fert_counter(p)
else
! this ensures no re-entry to onset of phase2
! b/c onset_counter(p) = onset_counter(p) - dt
! at every time step
onset_counter(p) = dt
end if
and
else ! crop not live
! next 2 lines conserve mass if leaf*_xfer > 0 due to interpinic
dwt_seedc_to_leaf(c) = dwt_seedc_to_leaf(c) - leafc_xfer(p)/dt
dwt_seedn_to_leaf(c) = dwt_seedn_to_leaf(c) - leafn_xfer(p)/dt
onset_counter(p) = 0._r8
If I understand correctly, this means that onset_counter = -dt from the point when croplive is true up until the first time step of leafout >= huileaf. At that point, onset_counter gets set to dt... and then to 0 when it next gets decremented.
--
For the most part, it looks like the fertilizer logic is probably working correctly, even though it's unintuitive.
But one thing that looks wrong is this: If ndays_on is long enough, and/or the croplive period short enough, such that ndays_on is longer than the croplive period, then fertilization will never get set to 0!
--
I feel like the fertilizer logic should be extracted from the general CNPhenology routine. We could introduce new variables signaling (1) what phase we're in, and (2) whether it's the first time step of the phase – or maybe: how many time steps into the phase we are. Then we could use those variables in the fertilizer routine.
Contributor guide
Assessment
This issue has not been assessed yet.