-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1557 from hut104/SoilNutrient
Soil Nutrient model for Mineralisation of C in three pools
- Loading branch information
Showing
15 changed files
with
2,556 additions
and
757 deletions.
There are no files selected for viewing
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Reflection; | ||
using Models.Core; | ||
|
||
namespace Models.PMF.Functions | ||
{ | ||
/// <summary> | ||
/// Bounds the child function between lower and upper bounds | ||
/// </summary> | ||
[Serializable] | ||
[Description("Bounds the child function between lower and upper bounds")] | ||
public class BoundFunction : Model, IFunction | ||
{ | ||
/// <summary>The child functions</summary> | ||
private List<IModel> ChildFunctions; | ||
|
||
[ChildLinkByName] | ||
IFunction Lower = null; | ||
|
||
[ChildLinkByName] | ||
IFunction Upper = null; | ||
|
||
/// <summary>Gets the value.</summary> | ||
/// <value>The value.</value> | ||
public double Value(int arrayIndex = -1) | ||
{ | ||
if (ChildFunctions == null) | ||
ChildFunctions = Apsim.Children(this, typeof(IFunction)); | ||
foreach (IFunction child in ChildFunctions) | ||
if (child != Lower && child != Upper) | ||
return Math.Max(Math.Min(Upper.Value(arrayIndex), child.Value(arrayIndex)),Lower.Value(arrayIndex)); | ||
throw new Exception("Cannot find function value to apply in bound"); | ||
} | ||
} | ||
} |
This file contains 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 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 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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Models.Core; | ||
using Models.Soils; | ||
using APSIM.Shared.Utilities; | ||
|
||
namespace Models.PMF.Functions | ||
{ | ||
/// <summary> | ||
/// A simple scale to convert soil water content into a value between 0 and 2 | ||
/// </summary> | ||
[Serializable] | ||
public class SoilWaterScale : Model, IFunction | ||
{ | ||
[Link] | ||
Soil Soil = null; | ||
|
||
/// <summary>Gets the value of the function.</summary> | ||
public double Value(int arrayIndex = -1) | ||
{ | ||
// temporary water factor (0-1) | ||
double wfd; | ||
if (Soil.SoilWater.SWmm[arrayIndex] > Soil.SoilWater.DULmm[arrayIndex]) | ||
{ // saturated | ||
wfd = Math.Max(1.0, Math.Min(2.0, 1.0 + | ||
MathUtilities.Divide(Soil.SoilWater.SWmm[arrayIndex] - Soil.SoilWater.DULmm[arrayIndex], Soil.SoilWater.SATmm[arrayIndex] - Soil.SoilWater.DULmm[arrayIndex], 0.0))); | ||
} | ||
else | ||
{ // unsaturated | ||
// assumes rate of mineralisation is at optimum rate until soil moisture midway between dul and ll15 | ||
wfd = Math.Max(0.0, Math.Min(1.0, MathUtilities.Divide(Soil.SoilWater.SWmm[arrayIndex] - Soil.SoilWater.LL15mm[arrayIndex], Soil.SoilWater.DULmm[arrayIndex] - Soil.SoilWater.LL15mm[arrayIndex], 0.0))); | ||
} | ||
|
||
return wfd; | ||
} | ||
|
||
} | ||
} |
This file contains 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 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 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 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,79 @@ | ||
| ||
namespace Models.Soils.Nutrient | ||
{ | ||
using Core; | ||
using Models.PMF.Functions; | ||
using System; | ||
using System.Reflection; | ||
|
||
/// <summary> | ||
/// Encapsulates a nitrogen flow between mineral N pools. | ||
/// </summary> | ||
[Serializable] | ||
[ValidParent(ParentType = typeof(Nutrient))] | ||
[PresenterName("UserInterface.Presenters.PropertyPresenter")] | ||
[ViewName("UserInterface.Views.GridView")] | ||
public class NFlow : Model | ||
{ | ||
private PropertyInfo sourceProperty; | ||
private PropertyInfo destinationProperty; | ||
|
||
[Link] | ||
private IFunction rate = null; | ||
|
||
[Link] | ||
private IFunction NLoss = null; | ||
|
||
[Link] | ||
private Nutrient nutrient = null; | ||
|
||
/// <summary> | ||
/// Name of source pool | ||
/// </summary> | ||
[Description("Name of source pool")] | ||
public string sourceName { get; set; } | ||
|
||
/// <summary> | ||
/// Name of destination pool | ||
/// </summary> | ||
[Description("Name of destination pool")] | ||
public string destinationName { get; set; } | ||
|
||
/// <summary>Performs the initial checks and setup</summary> | ||
/// <param name="sender">The sender.</param> | ||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> | ||
[EventSubscribe("Commencing")] | ||
private void OnSimulationCommencing(object sender, EventArgs e) | ||
{ | ||
sourceProperty = nutrient.GetType().GetProperty(sourceName); | ||
destinationProperty = nutrient.GetType().GetProperty(destinationName); | ||
} | ||
|
||
/// <summary> | ||
/// Get the information on potential residue decomposition - perform daily calculations as part of this. | ||
/// </summary> | ||
/// <param name="sender">The sender.</param> | ||
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> | ||
[EventSubscribe("DoSoilOrganicMatter")] | ||
private void OnDoSoilOrganicMatter(object sender, EventArgs e) | ||
{ | ||
|
||
double[] source = (double[])sourceProperty.GetValue(nutrient); | ||
|
||
double[] destination = (double[])destinationProperty.GetValue(nutrient); | ||
|
||
for (int i= 0; i < nutrient.NO3.Length; i++) | ||
{ | ||
double nitrogenFlow = rate.Value(i) * source[i]; | ||
double nitrogenFlowToDestination = nitrogenFlow * (1-NLoss.Value(i)); | ||
|
||
source[i] -= nitrogenFlow; | ||
destination[i] += nitrogenFlowToDestination; | ||
} | ||
sourceProperty.SetValue(nutrient, source); | ||
destinationProperty.SetValue(nutrient, destination); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.