Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sections to include in release notes:
### Fixed

### Changed
- SIPNET will now error instead of warning when an environment pool goes negative. This is a change from previous behavior where SIPNET would log a warning and continue running. (#398)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide/code-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Name fluxes by direction and target, e.g., `fluxes.NPP`, `fluxes.soilRespiration

- Apply all additions/removals in a consistent order if constraints require it (e.g., water first if it bounds biochemical rates next step).
- Enforce invariants:
- No negative pools; clamp with tracked deficits and warnings if needed.
- No negative pools; enforce with additional `ensureNonNegative()` call(s) in `ensureNonNegativeStocks()`.
- Mass conservation across linked pools (e.g., C/N stoichiometry) with balanced cross-pool transfers.
- Centralize any event-specific application here (e.g., harvest removing biomass, adding residues).

Expand Down
10 changes: 5 additions & 5 deletions src/sipnet/sipnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,11 +1348,11 @@ void calculateFluxes(void) {
// which var is treated as 0
void ensureNonNegative(double *var, double minVal, const char *label) {
if (*var < minVal) {
if (fabs(*var) > EPS) { // Don't print the zeros
logWarning(
"Non-negative stock constraint applied for %s (value %8.5f set "
"to zero) year %d day %d time %6.3f\n",
label, *var, climate->year, climate->day, climate->time);
if (*var < -EPS) { // Don't print the zeros
logError("Non-negative stock constraint violated for %s year %d day %d "
"time %6.3f\n",
label, *var, climate->year, climate->day, climate->time);
exit(EXIT_CODE_INTERNAL_ERROR);
}
*var = 0.;
}
Expand Down
Loading