diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index cdc5b4a6..5fe7e618 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/docs/developer-guide/code-structure.md b/docs/developer-guide/code-structure.md index b2d7b844..26730a76 100644 --- a/docs/developer-guide/code-structure.md +++ b/docs/developer-guide/code-structure.md @@ -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). diff --git a/src/sipnet/sipnet.c b/src/sipnet/sipnet.c index 5153c552..5b3a86b7 100644 --- a/src/sipnet/sipnet.c +++ b/src/sipnet/sipnet.c @@ -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.; }