-
Notifications
You must be signed in to change notification settings - Fork 32
SIP180 Adding N demand, fixation, and uptake #265
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6e37271
Adding N fixation and N uptake
83ae41e
Update CHANGELOG.md with PR #
eacb752
Adding N trackers, return in param files
e2bb471
Updating N demand calc, docs, params
45161ef
Pushing .out files
d71d5be
Merging with master
c491504
Fixing clang-format
194a461
Updating output after merge with master
b657c06
Merging with master
0765249
Updating output files
1dd8e5f
Updating N demand calc and docs
205a947
Merge branch 'master' into SIP180-Add-N-demand-and-fixation
599f1e4
Merging with master
d6b708f
Merging with master
99b6685
Merging with master
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
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 |
|---|---|---|
|
|
@@ -380,6 +380,8 @@ void readParamData(ModelParams **modelParamsPtr, const char *paramFile) { | |
| initializeOneModelParam(modelParams, "woodCN", &(params.woodCN), ctx.nitrogenCycle); | ||
| initializeOneModelParam(modelParams, "fineRootCN", &(params.fineRootCN), ctx.nitrogenCycle); | ||
| initializeOneModelParam(modelParams, "kCN", &(params.kCN), ctx.nitrogenCycle); | ||
| initializeOneModelParam(modelParams, "nFixationFracMax", &(params.nFixationFracMax), ctx.nitrogenCycle); | ||
| initializeOneModelParam(modelParams, "halfNFixationMax", &(params.halfNFixationMax), ctx.nitrogenCycle); | ||
|
|
||
| // New moisture dependency params | ||
| initializeOneModelParam(modelParams, "fAnoxia", &(params.fAnoxia), ctx.anaerobic || ctx.nitrogenCycle); | ||
|
|
@@ -433,7 +435,8 @@ void outputHeader(FILE *out) { | |
| fprintf(out, "npp nee cumNEE gpp rAboveground rSoil " | ||
| "rRoot ra rh rtot evapotranspiration "); | ||
| fprintf(out, "fluxestranspiration minN soilOrgN litterN n2o " | ||
| "nLeachFlux ch4 nppStorage bcdeltaC bcdeltaN\n"); | ||
| "nLeaching nFixation nUptake ch4 nppStorage bcdeltaC " | ||
| "bcdeltaN\n"); | ||
| } | ||
| /*! | ||
| * Print current state values to output file | ||
|
|
@@ -457,9 +460,10 @@ void outputState(FILE *out, int year, int day, double time) { | |
| trackers.npp, trackers.nee, trackers.totNee, trackers.gpp, | ||
| trackers.rAboveground, trackers.rSoil, trackers.rRoot, trackers.ra, | ||
| trackers.rh, trackers.rtot, trackers.evapotranspiration); | ||
| fprintf(out, "%19.4f %8.4f %9.4f %10.4f %9.6f %10.4f %8.4f", | ||
| fprintf(out, "%19.4f %8.4f %9.4f %10.4f %9.6f %9.4f %10.4f %8.4f %8.4f", | ||
| fluxes.transpiration, envi.minN, envi.soilOrgN, envi.litterN, | ||
| fluxes.nVolatilization, fluxes.nLeaching, trackers.methane); | ||
| fluxes.nVolatilization, trackers.nLeaching, trackers.nFixation, | ||
| trackers.nUptake, trackers.methane); | ||
| fprintf(out, "%12.4f %9.5f %9.5f\n", envi.plantWoodCStorageDelta, | ||
| balanceTracker.deltaC, balanceTracker.deltaN); | ||
| } | ||
|
|
@@ -1351,6 +1355,47 @@ void calcNLeachingFlux(void) { | |
| fluxes.nLeaching = envi.minN * phi * params.nLeachingFrac; | ||
| } | ||
|
|
||
| /*! | ||
| * Calculate plant N demand | ||
| */ | ||
| double calcPlantNDemand() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| // leafOnCreation is a transfer from the wood pool so | ||
| // demand should only count the difference in the N | ||
| // between those two pools, hence substracting | ||
| // params.woodCN from params.leafCN for leafOnCreation | ||
| double leafOnDemand = fluxes.leafOnCreation / params.leafCN - | ||
| fluxes.leafOnCreation / params.woodCN; | ||
| // calculate demand from all other creation terms | ||
| double creationDemand = fluxes.woodCreation / params.woodCN + | ||
| fluxes.leafCreation / params.leafCN + | ||
| fluxes.fineRootCreation / params.fineRootCN + | ||
| fluxes.coarseRootCreation / params.woodCN; | ||
| // total demand is leafOnDemand plus creationDemand | ||
| double totalDemand = leafOnDemand + creationDemand; | ||
| return totalDemand; | ||
| } | ||
|
|
||
| /*! | ||
| * Calculate plant N fixation and uptake fluxes | ||
| */ | ||
| void calcNFixationAndUptakeFluxes() { | ||
| double nFixationInhibition; | ||
| double nFixationFrac; | ||
| // Calculate inhibition of N fixation by soil mineral N | ||
| // using down-regulation function with increasing soil min N | ||
| // dimensionless between 0 and 1 | ||
| nFixationInhibition = | ||
| params.halfNFixationMax / (params.halfNFixationMax + envi.minN); | ||
| // Calculate fraction of plant N demand met by fixation | ||
| // dimensionless | ||
| nFixationFrac = params.nFixationFracMax * nFixationInhibition; | ||
| // Calculate N fixation flux | ||
| double nDemand = calcPlantNDemand(); | ||
| fluxes.nFixation = nFixationFrac * nDemand; | ||
| // Calculate N uptake flux | ||
| fluxes.nUptake = (1 - nFixationFrac) * nDemand; | ||
| } | ||
|
|
||
| /** | ||
| * Calculate nitrogen fluxes for soil and litter pools | ||
| */ | ||
|
|
@@ -1514,6 +1559,7 @@ void calculateFluxes(void) { | |
| if (ctx.nitrogenCycle) { | ||
| calcNVolatilizationFlux(); | ||
| calcNLeachingFlux(); | ||
| calcNFixationAndUptakeFluxes(); | ||
| calcNPoolFluxes(); | ||
| } | ||
| } | ||
|
|
@@ -1550,6 +1596,9 @@ void initTrackers(void) { | |
| trackers.rAboveground = 0.0; | ||
|
|
||
| trackers.yearlyLitter = 0.0; | ||
| trackers.nLeaching = 0.0; | ||
| trackers.nFixation = 0.0; | ||
| trackers.nUptake = 0.0; | ||
| } | ||
|
|
||
| // If var < minVal, then set var = 0 | ||
|
|
@@ -1662,6 +1711,11 @@ void updateTrackers(double oldSoilWater) { | |
| (oldSoilWater + envi.soilWater) / (2.0 * params.soilWHC); | ||
|
|
||
| trackers.yearlyLitter += fluxes.leafLitter; | ||
|
|
||
| // N cycle trackers | ||
| trackers.nLeaching = fluxes.nLeaching * climate->length; | ||
| trackers.nFixation = fluxes.nFixation * climate->length; | ||
| trackers.nUptake = fluxes.nUptake * climate->length; | ||
| } | ||
|
|
||
| void updateMeanTrackers(void) { | ||
|
|
@@ -1782,9 +1836,8 @@ void updateNitrogenPools(void) { | |
|
|
||
| // Soil mineral N (note we have one mineral pool for soil+litter) | ||
| // Mineral N additions from fertilization are handled with the events | ||
| // | ||
| // TODO: add plant uptake flux once implemented | ||
| envi.minN += (fluxes.nMin - fluxes.nVolatilization - fluxes.nLeaching) * | ||
| envi.minN += (fluxes.nMin - fluxes.nVolatilization - fluxes.nLeaching - | ||
| fluxes.nUptake) * | ||
| climate->length; | ||
|
|
||
| // Soil organic N | ||
|
|
||
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
Oops, something went wrong.
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.
Looks good!