SIP217 Update harvest and fert event handling#270
Merged
Conversation
Alomir
marked this pull request as ready for review
March 4, 2026 17:10
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates SIPNET’s agronomic event handling to correctly route harvest and fertilization transfers between litter vs soil pools, including the special case where litter_pool=off (issue #217).
Changes:
- Split harvest transfers into separate above-ground (litter) vs below-ground (soil) additions, with fallback routing to soil when
litter_pool=off. - Extend event flux tracking to include soil carbon and soil organic nitrogen event fluxes.
- Update tests and event-output fixtures to reflect the new event flux fields and behaviors; add a manual debug workflow.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/sipnet/events.c |
Implements new harvest/fert routing logic and emits additional event-output fields. |
src/sipnet/state.h |
Adds new event flux fields (eventSoilC, eventSoilOrgN) to the global flux struct. |
tests/sipnet/test_events_types/testEventHarvest.c |
Updates harvest tests to validate soil vs litter pool behavior and adds N-related expectations. |
tests/sipnet/test_events_types/testEventFertilization.c |
Ensures event output file is closed between runs (avoids leaking open handles). |
tests/sipnet/test_events_types/testEventPlanting.c |
Closes event output file after each run. |
tests/sipnet/test_events_types/testEventIrrigation.c |
Closes event output file after each run. |
tests/sipnet/test_events_types/testEventTillage.c |
Closes event output file after each run. |
tests/sipnet/test_events_types/events_two_harvest.in |
Adjusts the second harvest event fractions used by the harvest arithmetic test. |
tests/sipnet/test_events_infrastructure/events_output_no_header.out |
Updates expected event output to include soil C / soil org N fields for harvest. |
tests/sipnet/test_events_infrastructure/events_output_header.out |
Updates expected event output to include soil C / soil org N fields for harvest. |
.github/workflows/debug.yml |
Adds an opt-in workflow-dispatch tmate-based debug workflow on Linux. |
.github/workflows/ci.yml |
Minor whitespace-only change. |
Comments suppressed due to low confidence (2)
src/sipnet/events.c:575
- In FERTILIZATION, the code/comment say N is ignored when
nitrogenCycleis off, butorgN/minNare no longer zeroed in that case andwriteEventOut()still prints non-zeroeventOrgN,eventMinN, andeventInputN. This makes the event output misleading/inconsistent with the actual model state (fluxes.eventMinN/eventLitterN/eventInputNare not updated whennitrogenCycleis off). Consider explicitly settingorgN=minN=0when!ctx.nitrogenCycleand ensuring the values written toevents.outmatch what is actually applied.
const FertilizationParams *fertParams = gEvent->eventParams;
const double orgC = fertParams->orgC;
double orgN = fertParams->orgN;
double minN = fertParams->minN;
if (ctx.litterPool) {
fluxes.eventLitterC += orgC / climLen;
} else {
fluxes.eventSoilC += orgC / climLen;
}
if (ctx.nitrogenCycle) {
// As the warning says in readEventData(), we ignore N when the
// nitrogen cycle model is off
// Implies ctx.litterPool
fluxes.eventLitterN += orgN / climLen;
fluxes.eventMinN += minN / climLen;
}
// MASS BALANCE: this is a system input
fluxes.eventInputC += orgC / climLen;
if (ctx.nitrogenCycle) {
fluxes.eventInputN += (orgN + minN) / climLen;
}
writeEventOut(gEvent, 5, "fluxes.eventOrgN", orgN / climLen,
"fluxes.eventLitterC", orgC / climLen, "fluxes.eventMinN",
minN / climLen, "fluxes.eventInputC", orgC / climLen,
"fluxes.eventInputN", (orgN + minN) / climLen);
src/sipnet/events.c:575
- For FERTILIZATION when
ctx.litterPoolis off, carbon is now routed intofluxes.eventSoilC, but the output still labels the carbon term asfluxes.eventLitterCinwriteEventOut(). This contradicts the meaning ofeventLitterCinstate.hand can confuse debugging / downstream parsing ofevents.out. Consider writingfluxes.eventSoilCwhen litterPool is off (andfluxes.eventLitterCwhen on), or otherwise aligning the field names with the actual destination pool.
if (ctx.litterPool) {
fluxes.eventLitterC += orgC / climLen;
} else {
fluxes.eventSoilC += orgC / climLen;
}
if (ctx.nitrogenCycle) {
// As the warning says in readEventData(), we ignore N when the
// nitrogen cycle model is off
// Implies ctx.litterPool
fluxes.eventLitterN += orgN / climLen;
fluxes.eventMinN += minN / climLen;
}
// MASS BALANCE: this is a system input
fluxes.eventInputC += orgC / climLen;
if (ctx.nitrogenCycle) {
fluxes.eventInputN += (orgN + minN) / climLen;
}
writeEventOut(gEvent, 5, "fluxes.eventOrgN", orgN / climLen,
"fluxes.eventLitterC", orgC / climLen, "fluxes.eventMinN",
minN / climLen, "fluxes.eventInputC", orgC / climLen,
"fluxes.eventInputN", (orgN + minN) / climLen);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dlebauer
approved these changes
Mar 6, 2026
dlebauer
left a comment
Member
There was a problem hiding this comment.
LGTM!
I'm assuming the debugger action was intentionally checked in, wouldn't warrant a separate pr.
Collaborator
Author
|
Moving to draft to address copilot's comments |
Alomir
marked this pull request as draft
March 6, 2026 15:15
Alomir
marked this pull request as ready for review
March 6, 2026 15:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
How was this change tested?
Unit tests updated, including adding N handling for affected tests.
Smoke tests run; no updates needed, as we do not (yet) have harvest or fert events there.
Reproduction steps
N/A
Related issues
Checklist
docs/CHANGELOG.mdupdated with noteworthy changesclang-format(rungit clang-formatif needed)Note: See CONTRIBUTING.md for additional guidance. This repository uses automated formatting checks; if the pre-commit hook blocks your commit, run
git clang-formatto format staged changes.