Skip to content
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

9694 Renamed all Nconc to NConc #9695

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override List<ITag> Document(int none = 0)
Organ parentOrgan = FindParentOrgan(model.Parent);

// add a description of the equation for this function
section.Add(new Paragraph("<i>" + model.Name + " = [" + parentOrgan.Name + "].maximumNconc × (["
section.Add(new Paragraph("<i>" + model.Name + " = [" + parentOrgan.Name + "].maximumNConc × (["
+ parentOrgan.Name + "].Live.Wt + potentialAllocationWt) - [" + parentOrgan.Name + "].Live.N</i>"));
section.Add(new Paragraph("The demand for storage N is further reduced by a factor specified by the ["
+ parentOrgan.Name + "].NitrogenDemandSwitch."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override List<ITag> Document(int none = 0)
nDemandTags.AddRange(AutoDocumentation.DocumentModel(leafCohortParameters.MinimumNConc));
nDemandTags.Add(new Paragraph("Metabolic N demand is calculated as *PotentialMetabolicDMAllocation* * (*CriticalNConc* - *MinimumNConc*) where:"));
nDemandTags.AddRange(AutoDocumentation.DocumentModel(leafCohortParameters.CriticalNConc));
nDemandTags.Add(new Paragraph("Storage N demand is calculated as the sum of metabolic and structural wt (including todays demands) multiplied by *LuxaryNconc* (*MaximumNConc* - *CriticalNConc*) less the amount of storage N already present. *MaximumNConc* is given by:"));
nDemandTags.Add(new Paragraph("Storage N demand is calculated as the sum of metabolic and structural wt (including todays demands) multiplied by *LuxaryNConc* (*MaximumNConc* - *CriticalNConc*) less the amount of storage N already present. *MaximumNConc* is given by:"));
nDemandTags.AddRange(AutoDocumentation.DocumentModel(leafCohortParameters.MaximumNConc));
section.Add(new Section("Nitrogen Demand", nDemandTags));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override List<ITag> Document(int none = 0)
if (parentOrgan != null)
{
string organName = parentOrgan.Name;
section.Add(new Paragraph($"*{model.Name} = [{organName}].maximumNconc × ([{organName}].Live.Wt + potentialAllocationWt) - [{organName}].Live.N*"));
section.Add(new Paragraph($"*{model.Name} = [{organName}].maximumNConc × ([{organName}].Live.Wt + potentialAllocationWt) - [{organName}].Live.N*"));
section.Add(new Paragraph($"The demand for storage N is further reduced by a factor specified by the [{organName}].NitrogenDemandSwitch."));
}

Expand Down
6 changes: 3 additions & 3 deletions Models/AgPasture/PastureBelowGroundOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public class PastureBelowGroundOrgan : Model
internal double NDead { get { return Dead.DM.N; } }

/// <summary>Average N concentration in this organ (kg/kg).</summary>
internal double NconcTotal{ get { return MathUtilities.Divide(NTotal, DMTotal, 0.0); } }
internal double NConcTotal{ get { return MathUtilities.Divide(NTotal, DMTotal, 0.0); } }

/// <summary>Average N concentration in the live tissues (kg/kg).</summary>
internal double NconcLive { get { return MathUtilities.Divide(NLive, DMLive, 0.0); } }
internal double NConcLive { get { return MathUtilities.Divide(NLive, DMLive, 0.0); } }

/// <summary>Average N concentration in dead tissues (kg/kg).</summary>
internal double NconcDead { get { return MathUtilities.Divide(NDead, DMDead, 0.0); } }
internal double NConcDead { get { return MathUtilities.Divide(NDead, DMDead, 0.0); } }

/// <summary>Amount of luxury N available for remobilisation (kg/ha).</summary>
internal double NLuxuryRemobilisable { get { return Live.NRemobilisable; } }
Expand Down
101 changes: 100 additions & 1 deletion Models/Core/ApsimFile/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Models.Core.ApsimFile
public class Converter
{
/// <summary>Gets the latest .apsimx file format version.</summary>
public static int LatestVersion { get { return 188; } }
public static int LatestVersion { get { return 189; } }

/// <summary>Converts a .apsimx string to the latest version.</summary>
/// <param name="st">XML or JSON string to convert.</param>
Expand Down Expand Up @@ -6178,5 +6178,104 @@ private static void UpgradeToVersion188(JObject root, string _)
}
}
}

/// <summary>
/// Standardize NConc names so they all use NConc instead of a mix of NConc and Nconc
/// </summary>
/// <param name="root">The root JSON token.</param>
/// <param name="_">The name of the apsimx file.</param>
private static void UpgradeToVersion189(JObject root, string _)
{
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "Organ"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
organ["CritNConc"] = organ["CritNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "GenericOrgan"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
organ["CritNConc"] = organ["CritNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "HiReproductiveOrgan"))
{
organ["MinNConc"] = organ["MinNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "Leaf"))
{
organ["MinNConc"] = organ["MinNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "Nodule"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
organ["CritNConc"] = organ["CritNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "PerennialLeaf"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "ReproductiveOrgan"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "Root"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "SimpleLeaf"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
organ["CritNConc"] = organ["CritNconc"];
}
foreach (var organ in JsonUtilities.ChildrenRecursively(root, "SorghumLeaf"))
{
organ["MaxNConc"] = organ["MaxNconc"];
organ["MinNConc"] = organ["MinNconc"];
organ["CritNConc"] = organ["CritNconc"];
}
foreach (var report in JsonUtilities.ChildrenOfType(root, "Report"))
{
JsonUtilities.SearchReplaceReportVariableNames(report, ".MaxNconc", ".MaxNConc");
JsonUtilities.SearchReplaceReportVariableNames(report, ".MinNconc", ".MinNConc");
JsonUtilities.SearchReplaceReportVariableNames(report, ".CritNconc", ".CritNConc");
JsonUtilities.SearchReplaceReportVariableNames(report, ".Nconc", ".NConc");
JsonUtilities.SearchReplaceReportVariableNames(report, ".NconcTotal", ".NConcTotal");
JsonUtilities.SearchReplaceReportVariableNames(report, ".NconcLive", ".NConcLive");
JsonUtilities.SearchReplaceReportVariableNames(report, ".NconcDead", ".NConcDead");
}
foreach (var manager in JsonUtilities.ChildManagers(root))
{
bool changed = false;
if (manager.Replace(".MaxNconc", ".MaxNConc", caseSensitive: true))
changed = true;

if (manager.Replace(".MinNconc", ".MinNConc", caseSensitive: true))
changed = true;

if (manager.Replace(".CritNconc", ".CritNConc", caseSensitive: true))
changed = true;

if (manager.Replace(".Nconc", ".NConc", caseSensitive: true))
changed = true;

if (manager.Replace(".NconcTotal", ".NConcTotal", caseSensitive: true))
changed = true;

if (manager.Replace(".NconcLive", ".NConcLive", caseSensitive: true))
changed = true;

if (manager.Replace(".NconcDead", ".NConcDead", caseSensitive: true))
changed = true;

if (changed)
manager.Save();
}
}
}
}
10 changes: 5 additions & 5 deletions Models/Core/ApsimFile/XmlConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,21 +1330,21 @@ private static void MakeNDemandsNode(XmlNode node, XmlNode organNode)

//Add Structural demand function
XmlNode structural = XmlUtilities.CreateNode(node.OwnerDocument, "MultiplyFunction", "Structural");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(structural, "MinNconc", "[" + organNode.FirstChild.InnerText + "].minimumNconc.Value()");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(structural, "MinNConc", "[" + organNode.FirstChild.InnerText + "].minimumNConc.Value()");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(structural, "PotentialDMAllocation", "[" + organNode.FirstChild.InnerText + "].potentialDMAllocation.Structural");
NDemands.AppendChild(structural);
//Add Metabolic Demand function
XmlNode metabolic = XmlUtilities.CreateNode(node.OwnerDocument, "MultiplyFunction", "Metabolic");
XmlNode CritN = XmlUtilities.CreateNode(node.OwnerDocument, "SubtractFunction", "MetabolicNconc");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(CritN, "CritNconc", "[" + organNode.FirstChild.InnerText + "].criticalNConc.Value()");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(CritN, "MinNconc", "[" + organNode.FirstChild.InnerText + "].minimumNconc.Value()");
XmlNode CritN = XmlUtilities.CreateNode(node.OwnerDocument, "SubtractFunction", "MetabolicNConc");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(CritN, "CritNConc", "[" + organNode.FirstChild.InnerText + "].criticalNConc.Value()");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(CritN, "MinNConc", "[" + organNode.FirstChild.InnerText + "].minimumNConc.Value()");
metabolic.AppendChild(CritN);
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(metabolic, "PotentialDMAllocation", "[" + organNode.FirstChild.InnerText + "].potentialDMAllocation.Structural");
NDemands.AppendChild(metabolic);
//Add Storage Demand function
XmlNode Storage = XmlUtilities.CreateNode(node.OwnerDocument, "StorageNDemandFunction", "Storage");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(Storage, "NitrogenDemandSwitch", "[" + organNode.FirstChild.InnerText + "].nitrogenDemandSwitch.Value()");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(Storage, "MaxNconc", "[" + organNode.FirstChild.InnerText + "].maximumNconc.Value()");
ConverterUtilities.AddVariableReferenceFuntionIfNotExists(Storage, "MaxNConc", "[" + organNode.FirstChild.InnerText + "].maximumNConc.Value()");
NDemands.AppendChild(Storage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public void Allocate(IArbitration[] Organs, BiomassArbitrationType DM)
if (N.TotalAllocation[i] > TotalNDemand || MathUtilities.FloatsAreEqual(N.TotalAllocation[i], TotalNDemand))
N.ConstrainedGrowth[i] = 100000000; //given high value so where there is no N deficit in organ and N limitation to growth
else
if (N.TotalAllocation[i] == 0 | Organs[i].MinNconc == 0)
if (N.TotalAllocation[i] == 0 | Organs[i].MinNConc == 0)
N.ConstrainedGrowth[i] = 0;
else
N.ConstrainedGrowth[i] = N.TotalAllocation[i] / Organs[i].MinNconc;
N.ConstrainedGrowth[i] = N.TotalAllocation[i] / Organs[i].MinNConc;
}

// Reduce DM allocation below potential if insufficient N to reach Min n Conc or if DM was allocated to fixation
Expand Down
6 changes: 3 additions & 3 deletions Models/PMF/Arbitrator/SorghumArbitratorN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public double AllocateStructuralFromRachis(int iSupply, int iSink, BiomassArbitr
double dltNGreen = n.StructuralAllocation[iSupply] + n.MetabolicAllocation[iSupply];
double nConc = MathUtilities.Divide(source.Live.N, dmGreen + dltDmGreen, 0);
// dh - no point multiplying both numbers by 100 as we do in old apsim.
if (nConc < source.MinNconc)
if (nConc < source.MinNConc)
return 0;

n.StructuralAllocation[iSink] += StructuralAllocation;
Expand Down Expand Up @@ -248,7 +248,7 @@ public double AllocateStructuralFromStem(int iSupply, int iSink, BiomassArbitrat
// dh - no point multiplying both numbers by 100 as we do in old apsim.
// dh - need to make this check before providing any N.
double nConc = MathUtilities.Divide(source.Live.N, dmGreen + dltDmGreen, 0);
if (nConc < source.CritNconc)
if (nConc < source.CritNConc)
return 0;

if (dltNGreen > StructuralRequirement)
Expand All @@ -266,7 +266,7 @@ public double AllocateStructuralFromStem(int iSupply, int iSink, BiomassArbitrat
double availableN = n.RetranslocationSupply[iSupply] - n.Retranslocation[iSupply];

// cannot take below structural N
double structN = (dmGreen + dltDmGreen) * source.CritNconc;
double structN = (dmGreen + dltDmGreen) * source.CritNConc;
nAvailable = Math.Min(nAvailable, source.Live.N - structN);
nAvailable = Math.Max(nAvailable, 0);
nProvided += Math.Min(StructuralRequirement, nAvailable);
Expand Down
24 changes: 12 additions & 12 deletions Models/PMF/BiomassArbitration/Organ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ public IHasWaterDemand CanopyObjects
/// <summary>Gets the maximum N concentration.</summary>
[JsonIgnore]
[Units("g/g")]
public double MaxNconc { get; private set; }
public double MaxNConc { get; private set; }

/// <summary>Gets the minimum N concentration.</summary>
[JsonIgnore]
[Units("g/g")]
public double MinNconc { get; private set; }
public double MinNConc { get; private set; }

/// <summary>Gets the minimum N concentration.</summary>
[JsonIgnore]
[Units("g/g")]
public double CritNconc { get; private set; }
public double CritNConc { get; private set; }

/// <summary>Gets the total (live + dead) dry matter weight (g/m2)</summary>
[JsonIgnore]
Expand Down Expand Up @@ -260,7 +260,7 @@ public double N
/// <summary>Gets the total (live + dead) N concentration (g/g)</summary>
[JsonIgnore]
[Units("g/g")]
public double Nconc
public double NConc
{
get
{
Expand All @@ -275,7 +275,7 @@ public double Fn
{
get
{
return Live != null ? MathUtilities.Divide(Live.Nitrogen.Total, Live.Wt * MaxNconc, 1) : 0;
return Live != null ? MathUtilities.Divide(Live.Nitrogen.Total, Live.Wt * MaxNConc, 1) : 0;
}
}

Expand All @@ -286,7 +286,7 @@ public double FNmetabolic
{
get
{
return (Live != null) ? Math.Min(1.0, MathUtilities.Divide(Nconc - MinNconc, CritNconc - MinNconc, 0)) : 0;
return (Live != null) ? Math.Min(1.0, MathUtilities.Divide(NConc - MinNConc, CritNConc - MinNConc, 0)) : 0;
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ public void initialiseBiomass()
{
Clear();
ClearBiomassFlows();
setNconcs();
setNConcs();
Nitrogen.setConcentrationsOrProportions();
Carbon.setConcentrationsOrProportions();

Expand Down Expand Up @@ -449,7 +449,7 @@ protected virtual void OnDoPotentialPlantGrowth(object sender, EventArgs e)
//Do initial calculations
SenescenceRate = Math.Min(senescenceRate.Value(),1);
DetachmentRate = Math.Min(detachmentRate.Value(),1);
setNconcs();
setNConcs();
Carbon.SetSuppliesAndDemands();
}
}
Expand Down Expand Up @@ -614,11 +614,11 @@ private void reset()
}
}

private void setNconcs()
private void setNConcs()
{
MaxNconc = Nitrogen.ConcentrationOrFraction != null ? Nitrogen.ConcentrationOrFraction.Storage : 0;
MinNconc = Nitrogen.ConcentrationOrFraction != null ? Nitrogen.ConcentrationOrFraction.Structural : 0;
CritNconc = Nitrogen.ConcentrationOrFraction != null ? Nitrogen.ConcentrationOrFraction.Metabolic : 0;
MaxNConc = Nitrogen.ConcentrationOrFraction != null ? Nitrogen.ConcentrationOrFraction.Storage : 0;
MinNConc = Nitrogen.ConcentrationOrFraction != null ? Nitrogen.ConcentrationOrFraction.Structural : 0;
CritNConc = Nitrogen.ConcentrationOrFraction != null ? Nitrogen.ConcentrationOrFraction.Metabolic : 0;
}
}
}
2 changes: 1 addition & 1 deletion Models/PMF/Interfaces/IArbitration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface IArbitration
void SetNitrogenAllocation(BiomassAllocationType nitrogen);

/// <summary>Gets or sets the minimum nconc.</summary>
double MinNconc { get; }
double MinNConc { get; }

/// <summary>Gets or sets the n fixation cost.</summary>
double NFixationCost { get; }
Expand Down
8 changes: 4 additions & 4 deletions Models/PMF/Organs/GenericOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,17 @@ public GenericOrgan()
/// <summary>Gets the maximum N concentration.</summary>
[JsonIgnore]
[Units("g/g")]
public double MaxNconc { get { return maximumNConc.Value(); } }
public double MaxNConc { get { return maximumNConc.Value(); } }

/// <summary>Gets the minimum N concentration.</summary>
[JsonIgnore]
[Units("g/g")]
public double MinNconc { get { return minimumNConc.Value(); } }
public double MinNConc { get { return minimumNConc.Value(); } }

/// <summary>Gets the minimum N concentration.</summary>
[JsonIgnore]
[Units("g/g")]
public double CritNconc { get { return criticalNConc.Value(); } }
public double CritNConc { get { return criticalNConc.Value(); } }

/// <summary>Gets the total (live + dead) dry matter weight (g/m2)</summary>
[JsonIgnore]
Expand All @@ -232,7 +232,7 @@ public GenericOrgan()
/// <summary>Gets the total (live + dead) N concentration (g/g)</summary>
[JsonIgnore]
[Units("g/g")]
public double Nconc
public double NConc
{
get
{
Expand Down
2 changes: 1 addition & 1 deletion Models/PMF/Organs/HIReproductiveOrgan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void SetDryMatterPotentialAllocation(BiomassPoolType dryMatter) { }

/// <summary>Minimum N concentration</summary>
[JsonIgnore]
public double MinNconc { get { return 0; } }
public double MinNConc { get { return 0; } }

/// <summary>A list of material (biomass) that can be damaged.</summary>
public IEnumerable<DamageableBiomass> Material
Expand Down
4 changes: 2 additions & 2 deletions Models/PMF/Organs/Leaf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public double LAIBranch

/// <summary>Gets the total (live + dead) N concentration (g/g)</summary>
[JsonIgnore]
public double Nconc
public double NConc
{
get
{
Expand Down Expand Up @@ -1762,7 +1762,7 @@ public void SetNitrogenAllocation(BiomassAllocationType nitrogen)
}

/// <summary>Gets or sets the minimum nconc.</summary>
public double MinNconc
public double MinNConc
{
get
{
Expand Down
Loading