-
Notifications
You must be signed in to change notification settings - Fork 17
Update events.out, sipnet.out, and irrigation / water balance documentation #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,000
−688
Merged
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e408000
Switches events to flux model, ensures smoke test output has not changed
Alomir 3ef5df4
Updates to keep output unchanged
Alomir 3b3f85e
Updates event handler for proper flux handling
Alomir 340e870
Updates event handler for proper flux handling
Alomir d5d16a5
Updates for tests for retool-events-as-fluxes
Alomir 8c71672
Enables exclusion check for events/microbes
Alomir 4f101d5
Minor comment updates
Alomir dc358d8
Expand irrigation and water dynamics documentation; clarify event pro…
dlebauer 9252451
Merge branch 'master' into SIP147-retool-events-as-fluxes
dlebauer 528f511
Merge branch 'SIP147-retool-events-as-fluxes' into 148_doc_updates
dlebauer ac331b7
formatting
dlebauer 30061dd
more formatting
dlebauer 1d99aac
Merge branch 'master' into 148_doc_updates
dlebauer 8e0ccb8
Update docs/.alternate-model-structure-ideas.md
dlebauer d227753
fixed typos and updated doc of drainage
dlebauer d59b5db
Merge branch '148_doc_updates' of github.com:pecanproject/sipnet into…
dlebauer f68674f
update typo F_vol
dlebauer fae1509
typos
dlebauer 4e69876
Add DOI badge to README
dlebauer dcb7636
Add documentation for model outputs, parameters, logging; update navi…
dlebauer da00346
Merge branch '148_doc_updates' of github.com:pecanproject/sipnet into…
dlebauer 1186237
Merge branch 'master' into 148_doc_updates
dlebauer a80f449
148 even more doc updates (#159)
dlebauer 0136fa8
Tweaks and updates
Alomir b003664
Removes duplicate doc
Alomir 820e067
Minor tweaks
Alomir 589100d
Minor tweaks
Alomir 0801395
Merge branch 'master' into 148_doc_updates
Alomir cd3fec2
Make turnover params consistently per-year
Alomir 542812c
Merge branch 'master' into 148_doc_updates
Alomir b838c27
Dummy action when linter not triggered
Alomir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Code Structure | ||
|
||
This guide documents how state is advanced each timestep and the conventions that keep flux calculations pure and pool updates centralized. | ||
|
||
## Timestep Phases (in `updateState()`) | ||
|
||
1) Initialize fluxes | ||
- Zero all `fluxes.*` and `fluxes.event*`. | ||
|
||
2) Compute fluxes (pure calculations) | ||
- `calculateFluxes()` computes photosynthesis, respiration, water/snow, etc. | ||
- `processEvents()` converts scheduled/instant events to `fluxes.event*` deltas (no pool mutation). | ||
- `soilDegradation()` and other biogeochemical modules compute additional flux rates only (no pool mutation). | ||
- No function in this phase mutates `envi.*` or `trackers.*`. | ||
|
||
3) Apply pool updates (single place) | ||
- `applyPoolUpdates()` is the only code that changes `envi.*`. | ||
- For each pool P: ΔP = (sum of rate fluxes to P) * climate.length + (sum of `fluxes.event*` deltas to P). | ||
- Apply bounds, conservation, and cross-pool constraints here. | ||
|
||
4) Trackers and running means | ||
- `updateTrackers()` uses timestep-integrated values (rate * climate.length) plus event deltas. | ||
|
||
5) Output | ||
- `outputState()` and any optional diagnostics/logging. | ||
|
||
### Pseudocode outline | ||
|
||
- updateState(): | ||
- zeroFluxes() | ||
- calculateFluxes() // pure rates | ||
- processEvents() // sets fluxes.event* deltas only | ||
- soilDegradation() // pure rates | ||
- applyPoolUpdates() // the only place that mutates envi.* | ||
- updateTrackers() | ||
- outputState() | ||
|
||
## Mutability Rules (must-follow) | ||
|
||
- Only `applyPoolUpdates()` may change `envi.*`. | ||
- Flux calculators: | ||
- May read `envi.*`, `params.*`, `ctx.*`, `climate.*`. | ||
- May write `fluxes.*` (rates) and `fluxes.event*` (event deltas). | ||
- Must not mutate `envi.*`, `trackers.*`, or perform I/O as logic side-effects. | ||
- Events never change pools directly; they only add to `fluxes.event*`. | ||
|
||
## Units and Integration | ||
|
||
- Rate fluxes in `fluxes.*` are per-day rates (pool units per day). | ||
- Event deltas in `fluxes.event*` are direct pool deltas (same units as pools), not rates. | ||
- Integration per pool each timestep: | ||
- Δpool_from_rates = (sum of relevant `fluxes.*`) * climate.length | ||
- Δpool_from_events = (sum of relevant `fluxes.event*`) | ||
- pool += Δpool_from_rates + Δpool_from_events | ||
|
||
## Naming Conventions | ||
|
||
- envi.* State variables (pools, water, snow, canopy, soil layers). | ||
- fluxes.* Per-day flux rates computed in the flux phase. | ||
- fluxes.event* Instantaneous/event deltas to be applied during pool update. | ||
- trackers.* Integrated timestep values, cumulative sums, yearly aggregates. | ||
- params.* Fixed run parameters (immutable during a run). | ||
- ctx.* Feature flags / configuration switches. | ||
- climate.* Forcing for the current timestep (e.g., length, met drivers). | ||
- diag.* Optional transient diagnostics (no side effects on state). | ||
|
||
Name fluxes by direction and target, e.g., `fluxes.NPP`, `fluxes.soilRespiration`, `fluxes.leafLitterToSoil`, `fluxes.eventHarvestC`. Prefer “to/from” clarity for transfers. | ||
|
||
## Pool Update Responsibilities | ||
|
||
- 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. | ||
- 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). | ||
|
||
## Adding a New Flux or Event | ||
|
||
- Rates: add a `fluxes.*` variable, compute it in a flux function, and integrate it in `applyPoolUpdates()`. | ||
- Events: add a `fluxes.event*` delta, accumulate in `processEvents()`, apply it in `applyPoolUpdates()`. | ||
- Do not mutate `envi.*` in calculators or event processors. | ||
|
||
## Logging & Errors | ||
|
||
- Use `logError()` and `logWarning()` (not printf) so tests can capture output. | ||
- Messages should include timestep context: year, day, event type (if relevant), and the offending value(s). | ||
- Emit warnings on clamping, conservation corrections, or unexpected negative fluxes. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
# Logging | ||
|
||
SIPNET's logger is defined in `common/logger.h` and implemented in `common/logger.c`. | ||
SIPNET's logger is a small wrapper around `printf` that adds standard prefixes and, for internal errors, the source file and line number. It is defined in `common/logging.h` and implemented in `common/logging.c`. | ||
|
||
It provides a simple interface for logging messages at different levels (e.g., debug, info, warning, error). | ||
## Levels | ||
|
||
The use of logger functions is preferred over `printf` because ... | ||
It is appropriate to use printf when ... | ||
|
||
## Logging Levels | ||
|
||
- **logDebug**: Information useful during development or debugging. | ||
- **logInfo**: General information about the program's execution, such as successful initialization or key milestones. | ||
- **logWarning**: Non-critical issues that might require attention but do not stop execution. Example: deprecated parameters or ignored input. | ||
- **logError**: Critical issues that prevent the program from continuing correctly. Example: missing required parameters or internal errors. | ||
- 0: Quiet-able (suppressed by `--quiet`). | ||
- 1: Always on (not suppressed). | ||
- 2: Always on and includes `file:line`. | ||
|
||
|
||
## Usage | ||
|
||
1. Include the logger header in your source file: | ||
- logInfo: Level 0; routine progress, configuration summaries, expected state changes. | ||
- logWarning: Level 0; Recoverable issues or surprises; fallbacks, deprecated/ignored inputs. | ||
- logTest: Level 1; Deterøinistic messages for tests/CI; not user-facing. | ||
- logError: Level 1; Non-recoverable problems preventing correct operation; abort/exit or skip major task. | ||
- logInternalError: Level 2; Errors that should never happen; include details and ask to report. | ||
|
||
1. Include the header: | ||
```c | ||
#include "common/logger.h" | ||
#include "common/logging.h" | ||
``` | ||
|
||
2. Use the logging functions to log messages at different levels: | ||
2. Log messages: | ||
```c | ||
// Log messages at different levels | ||
logDebug("This is a debug message"); | ||
logInfo("This is an info message"); | ||
logWarning("This is a warning message"); | ||
logError("This is an error message"); | ||
logInfo("Initialized OK\n"); | ||
logWarning("Deprecated parameter: %s\n", name); | ||
logTest("Iteration %d\n", i); | ||
logError("Missing required parameter: %s\n", key); | ||
logInternalError("Unexpected state: %d\n", code); | ||
``` | ||
3. Example outputs: | ||
``` | ||
[INFO ] Initialized OK | ||
[WARNING] Deprecated parameter: foo | ||
[TEST ] Iteration 12 | ||
[ERROR ] Missing required parameter: bar | ||
[ERROR (INTERNAL)] (myfile.c:123) Unexpected state: 5 | ||
``` | ||
|
||
|
||
## Notes: | ||
|
||
- Each log prints a fixed prefix (e.g., `[INFO ]`, `[WARNING]`, `[ERROR ]`). | ||
- Messages use `printf`-style formatting. Include `\n` yourself if you want a newline. | ||
- Level 2 (`logInternalError`) prints file:line; levels 0–1 print just the prefix. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!