//----------------------- Public methods ----------------------- /// <summary>Initialise this root instance (and tissues).</summary> /// <param name="zone">The zone the roots belong to.</param> /// <param name="minimumLiveWt">Minimum live DM biomass for this organ (kg/ha).</param> public void Initialise(Zone zone, double minimumLiveWt) { // link to soil models parameters soil = zone.FindInScope <Soil>(); if (soil == null) { throw new Exception($"Cannot find soil in zone {zone.Name}"); } soilPhysical = soil.FindInScope <IPhysical>(); if (soilPhysical == null) { throw new Exception($"Cannot find soil physical in soil {soil.Name}"); } waterBalance = soil.FindInScope <ISoilWater>(); if (waterBalance == null) { throw new Exception($"Cannot find a water balance model in soil {soil.Name}"); } soilCropData = soil.FindDescendant <SoilCrop>(species.Name + "Soil"); if (soilCropData == null) { throw new Exception($"Cannot find a soil crop parameterisation called {species.Name + "Soil"}"); } nutrient = zone.FindInScope <INutrient>(); if (nutrient == null) { throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}"); } no3 = zone.FindInScope("NO3") as ISolute; if (no3 == null) { throw new Exception($"Cannot find NO3 solute in zone {zone.Name}"); } nh4 = zone.FindInScope("NH4") as ISolute; if (nh4 == null) { throw new Exception($"Cannot find NH4 solute in zone {zone.Name}"); } // initialise soil related variables zoneName = soil.Parent.Name; nLayers = soilPhysical.Thickness.Length; mySoilNH4Available = new double[nLayers]; mySoilNO3Available = new double[nLayers]; mySoilWaterAvailable = new double[nLayers]; // save minimum DM and get target root distribution MinimumLiveDM = minimumLiveWt; TargetDistribution = RootDistributionTarget(); // initialise tissues Live.Initialise(); Dead.Initialise(); }
/// <summary>Initialises this instance.</summary> public void Initialise() { NO3Solute = Apsim.Find(soilInZone, "NO3") as ISolute; NH4Solute = Apsim.Find(soilInZone, "NH4") as ISolute; PlantAvailableNO3Solute = Apsim.Find(soilInZone, "PlantAvailableNO3") as ISolute; PlantAvailableNH4Solute = Apsim.Find(soilInZone, "PlantAvailableNH4") as ISolute; }
/// <summary>Constructor</summary> /// <param name="Plant">The parant plant</param> /// <param name="Root">The parent root organ</param> /// <param name="soil">The soil in the zone.</param> /// <param name="depth">Root depth (mm)</param> /// <param name="initialDM">Initial dry matter</param> /// <param name="population">plant population</param> /// <param name="maxNConc">maximum n concentration</param> /// <param name="rfv">Root front velocity</param> /// <param name="mrd">Maximum root depth</param> /// <param name="remobCost">Remobilisation cost</param> public ZoneState(Plant Plant, Root Root, Soil soil, double depth, BiomassDemand initialDM, double population, double maxNConc, IFunction rfv, IFunction mrd, IFunction remobCost) { this.Soil = soil; this.plant = Plant; this.root = Root; this.rootFrontVelocity = rfv; this.maximumRootDepth = mrd; this.remobilisationCost = remobCost; Physical = soil.FindChild <IPhysical>(); WaterBalance = soil.FindChild <ISoilWater>(); IsWeirdoPresent = soil.FindChild("Weirdo") != null; Clear(); Zone zone = soil.FindAncestor <Zone>(); if (zone == null) { throw new Exception("Soil " + soil + " is not in a zone."); } NO3 = zone.FindInScope <ISolute>("NO3"); NH4 = zone.FindInScope <ISolute>("NH4"); Name = zone.Name; Initialise(depth, initialDM, population, maxNConc); }
/// <summary> /// Constructor. Copy state from another instance. /// </summary> /// <param name="from">The instance to copy from.</param> public ZoneWaterAndN(ZoneWaterAndN from) { NO3Solute = from.NO3Solute; NH4Solute = from.NH4Solute; soilInZone = from.soilInZone; Zone = from.Zone; Water = from.Water; NO3N = from.NO3N; NH4N = from.NH4N; }
/// <summary>Constructor, initialise tissues for the roots.</summary> /// <param name="zone">The zone the roots belong in.</param> /// <param name="initialDM">Initial dry matter weight</param> /// <param name="initialDepth">Initial root depth</param> /// <param name="minLiveDM">The minimum biomass for this organ</param> public void Initialise(Zone zone, double initialDM, double initialDepth, double minLiveDM) { soil = zone.FindInScope <Soil>(); if (soil == null) { throw new Exception($"Cannot find soil in zone {zone.Name}"); } nutrient = zone.FindInScope <INutrient>(); if (nutrient == null) { throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}"); } no3 = zone.FindInScope("NO3") as ISolute; if (no3 == null) { throw new Exception($"Cannot find NO3 solute in zone {zone.Name}"); } nh4 = zone.FindInScope("NH4") as ISolute; if (nh4 == null) { throw new Exception($"Cannot find NH4 solute in zone {zone.Name}"); } // save the parameters for this organ nLayers = soil.Thickness.Length; minimumLiveDM = minLiveDM; dulMM = soil.DULmm; ll15MM = soil.LL15mm; Live = tissue[0]; Dead = tissue[1]; // Link to soil and initialise variables zoneName = soil.Parent.Name; mySoilNH4Available = new double[nLayers]; mySoilNO3Available = new double[nLayers]; // Initialise root DM, N, depth, and distribution Depth = initialDepth; CalculateRootZoneBottomLayer(); TargetDistribution = RootDistributionTarget(); double[] initialDMByLayer = MathUtilities.Multiply_Value(CurrentRootDistributionTarget(), initialDM); double[] initialNByLayer = MathUtilities.Multiply_Value(initialDMByLayer, NConcOptimum); // Initialise the live tissue. Live.Initialise(initialDMByLayer, initialNByLayer); Dead.Initialise(null, null); }
/// <summary>Initialises this instance.</summary> public void Initialise() { NO3Solute = soilInZone.FindInScope <ISolute>("NO3"); NH4Solute = soilInZone.FindInScope <ISolute>("NH4"); var PlantAvailableNO3Solute = soilInZone.FindInScope <ISolute>("PlantAvailableNO3"); if (PlantAvailableNO3Solute != null) { NO3Solute = PlantAvailableNO3Solute; } var PlantAvailableNH4Solute = soilInZone.FindInScope <ISolute>("PlantAvailableNH4"); if (PlantAvailableNH4Solute != null) { NH4Solute = PlantAvailableNH4Solute; } }
/// <summary>Constructor</summary> /// <param name="Plant">The parant plant</param> /// <param name="Root">The parent root organ</param> /// <param name="soil">The soil in the zone.</param> /// <param name="depth">Root depth (mm)</param> /// <param name="initialDM">Initial dry matter</param> /// <param name="population">plant population</param> /// <param name="maxNConc">maximum n concentration</param> /// <param name="rfv">Root front velocity</param> /// <param name="mrd">Maximum root depth</param> /// <param name="remobCost">Remobilisation cost</param> public ZoneState(Plant Plant, Root Root, Soil soil, double depth, double initialDM, double population, double maxNConc, IFunction rfv, IFunction mrd, IFunction remobCost) { this.soil = soil; this.plant = Plant; this.root = Root; this.rootFrontVelocity = rfv; this.maximumRootDepth = mrd; this.remobilisationCost = remobCost; Clear(); Zone zone = Apsim.Parent(soil, typeof(Zone)) as Zone; if (zone == null) { throw new Exception("Soil " + soil + " is not in a zone."); } NO3 = Apsim.Find(zone, "NO3") as ISolute; NH4 = Apsim.Find(zone, "NH4") as ISolute; Name = zone.Name; Initialise(depth, initialDM, population, maxNConc); }
private void OnDoSoilOrganicMatter(object sender, EventArgs e) { if (sourceSolute == null) { sourceSolute = FindInScope <ISolute>(Parent.Name); destinationSolute = FindInScope <ISolute>(destinationName); } double[] source = sourceSolute.kgha; int numLayers = source.Length; if (Value == null) { Value = new double[source.Length]; } double[] destination = null; if (destinationName != null) { destination = destinationSolute.kgha; } for (int i = 0; i < numLayers; i++) { double phosphorusFlow = 0; if (source[i] > 0) { phosphorusFlow = rate.Value(i) * source[i]; } source[i] -= phosphorusFlow; Value[i] = phosphorusFlow; destination[i] += phosphorusFlow; } sourceSolute.SetKgHa(SoluteSetterType.Soil, source); destinationSolute.SetKgHa(SoluteSetterType.Soil, destination); }
private void OnCommencing(object sender, EventArgs args) { if (sourceSolute == null) { sourceSolute = FindInScope <ISolute>(Parent.Name); destinationSolute = FindInScope <ISolute>(destinationName); } double[] source = sourceSolute.kgha; int numLayers = source.Length; if (Value == null) { Value = new double[source.Length]; } if (Natm == null) { Natm = new double[source.Length]; } if (N2Oatm == null) { N2Oatm = new double[source.Length]; } }
/// <summary>Constructor, initialise tissues for the roots.</summary> /// <param name="zone">The zone the roots belong in.</param> /// <param name="initialDM">Initial dry matter weight</param> /// <param name="initialDepth">Initial root depth</param> /// <param name="minLiveDM">The minimum biomass for this organ</param> public void Initialise(Zone zone, double initialDM, double initialDepth, double minLiveDM) { soil = zone.FindInScope <Soil>(); if (soil == null) { throw new Exception($"Cannot find soil in zone {zone.Name}"); } soilPhysical = soil.FindInScope <IPhysical>(); if (soilPhysical == null) { throw new Exception($"Cannot find soil physical in soil {soil.Name}"); } waterBalance = soil.FindInScope <ISoilWater>(); if (waterBalance == null) { throw new Exception($"Cannot find a water balance model in soil {soil.Name}"); } soilCropData = soil.FindDescendant <SoilCrop>(species.Name + "Soil"); if (soilCropData == null) { throw new Exception($"Cannot find a soil crop parameterisation called {species.Name + "Soil"}"); } nutrient = zone.FindInScope <INutrient>(); if (nutrient == null) { throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}"); } no3 = zone.FindInScope("NO3") as ISolute; if (no3 == null) { throw new Exception($"Cannot find NO3 solute in zone {zone.Name}"); } nh4 = zone.FindInScope("NH4") as ISolute; if (nh4 == null) { throw new Exception($"Cannot find NH4 solute in zone {zone.Name}"); } // link to soil and initialise related variables zoneName = soil.Parent.Name; nLayers = soilPhysical.Thickness.Length; dulMM = soilPhysical.DULmm; ll15MM = soilPhysical.LL15mm; mySoilNH4Available = new double[nLayers]; mySoilNO3Available = new double[nLayers]; // save minimum DM and get target root distribution Depth = initialDepth; minimumLiveDM = minLiveDM; CalculateRootZoneBottomLayer(); TargetDistribution = RootDistributionTarget(); // initialise tissues double[] initialDMByLayer = MathUtilities.Multiply_Value(CurrentRootDistributionTarget(), initialDM); double[] initialNByLayer = MathUtilities.Multiply_Value(initialDMByLayer, NConcOptimum); Live = tissue[0]; Dead = tissue[1]; Live.Initialise(initialDMByLayer, initialNByLayer); Dead.Initialise(null, null); }
private void OnSimulationCommencing(object sender, EventArgs e) { NO3Solute = Apsim.Find(this, "NO3") as ISolute; NH4Solute = Apsim.Find(this, "NH4") as ISolute; Reset(); }
private void OnDoSoilOrganicMatter(object sender, EventArgs e) { if (sourceSolute == null) { sourceSolute = FindInScope <ISolute>(Parent.Name); destinationSolute = FindInScope <ISolute>(destinationName); } double[] source = sourceSolute.kgha; int numLayers = source.Length; if (Value == null) { Value = new double[source.Length]; } if (Natm == null) { Natm = new double[source.Length]; } if (N2Oatm == null) { N2Oatm = new double[source.Length]; } double[] destination = null; if (destinationName != null) { destination = destinationSolute.kgha; } for (int i = 0; i < numLayers; i++) { double nitrogenFlow = 0; if (source[i] > 0) { nitrogenFlow = rate.Value(i) * source[i]; } if (nitrogenFlow > 0) { Natm[i] = nitrogenFlow * NLoss.Value(i); // keep value of loss for use in output } else { Natm[i] = 0; } if (Natm[i] > 0) { N2Oatm[i] = Natm[i] * N2OFraction.Value(i); } else { N2Oatm[i] = 0; } double nitrogenFlowToDestination = nitrogenFlow - Natm[i]; if (destination == null && NLoss.Value(i) != 1) { throw new Exception("N loss fraction for N flow must be 1 if no destination is specified."); } source[i] -= nitrogenFlow; Value[i] = nitrogenFlowToDestination; // keep value of flow for use in output if (destination != null) { destination[i] += nitrogenFlowToDestination; } } sourceSolute.SetKgHa(SoluteSetterType.Soil, source); if (destination != null) { destinationSolute.SetKgHa(SoluteSetterType.Soil, destination); } }
private void OnSimulationCommencing(object sender, EventArgs e) { sourceSolute = Apsim.Find(this, Parent.Name) as ISolute; destinationSolute = Apsim.Find(this, destinationName) as ISolute; }
/// <summary>Constructor, initialise tissues for the roots.</summary> /// <param name="nameOfSpecies">Name of the pasture species</param> /// <param name="numTissues">Number of tissues in this organ</param> /// <param name="initialDM">Initial dry matter weight</param> /// <param name="initialDepth">Initial root depth</param> /// <param name="optNconc">The optimum N concentration</param> /// <param name="minNconc">The minimum N concentration</param> /// <param name="maxNconc">The maximum N concentration</param> /// <param name="minLiveDM">The minimum biomass for this organ</param> /// <param name="specificRootLength">The specific root length (m/g)</param> /// <param name="rootDepthMaximum">The maximum root depth</param> /// <param name="rootDistributionDepthParam">Parameter to compute root distribution, depth with constant root</param> /// <param name="rootBottomDistributionFactor">Parameter to compute root distribution, </param> /// <param name="rootDistributionExponent">Parameter to compute root distribution, exponent for root decrease</param> /// <param name="waterAvailableMethod">Method to compute water available</param> /// <param name="nitrogenAvailableMethod">Method to compute N available</param> /// <param name="kNH4">Parameter to compute NN4 available, default method</param> /// <param name="kNO3">Parameter to compute NO3 available, default method</param> /// <param name="maxNUptake">Parameter to compute N uptake, default method</param> /// <param name="kuNH4">Parameter to compute NH4 available, alternative method</param> /// <param name="kuNO3">Parameter to compute NO3 available, alternative method</param> /// <param name="referenceKSuptake">Parameter to compute available water, conductivity</param> /// <param name="referenceRLD">Parameter to compute available water, roots</param> /// <param name="exponentSoilMoisture">Parameter to compute available water</param> /// <param name="theSoil">Reference to the soil in the zone these roots are in</param> public PastureBelowGroundOrgan(string nameOfSpecies, int numTissues, double initialDM, double initialDepth, double optNconc, double minNconc, double maxNconc, double minLiveDM, double specificRootLength, double rootDepthMaximum, double rootDistributionDepthParam, double rootDistributionExponent, double rootBottomDistributionFactor, PastureSpecies.PlantAvailableWaterMethod waterAvailableMethod, PastureSpecies.PlantAvailableNitrogenMethod nitrogenAvailableMethod, double kNH4, double kNO3, double maxNUptake, double kuNH4, double kuNO3, double referenceKSuptake, double referenceRLD, double exponentSoilMoisture, Soil theSoil) { mySoil = theSoil; SoilNitrogen = Apsim.Find(mySoil, typeof(INutrient)) as INutrient; if (SoilNitrogen == null) { throw new Exception("Cannot find SoilNitrogen in zone"); } // Typically two tissues below ground, one live and one dead Tissue = new RootTissue[numTissues]; nLayers = theSoil.Thickness.Length; for (int t = 0; t < Tissue.Length; t++) { Tissue[t] = new RootTissue(nameOfSpecies, SoilNitrogen, nLayers); } // save the parameters for this organ mySpeciesName = nameOfSpecies; NConcOptimum = optNconc; NConcMinimum = minNconc; NConcMaximum = maxNconc; MinimumLiveDM = minLiveDM; mySpecificRootLength = specificRootLength; myRootDepthMaximum = rootDepthMaximum; myRootDistributionDepthParam = rootDistributionDepthParam; myRootDistributionExponent = rootDistributionExponent; myRootBottomDistributionFactor = rootBottomDistributionFactor; myWaterAvailableMethod = waterAvailableMethod; myNitrogenAvailableMethod = nitrogenAvailableMethod; myKNO3 = kNO3; myKNH4 = kNH4; myMaximumNUptake = maxNUptake; myKuNH4 = kuNH4; myKuNO3 = kuNO3; myReferenceKSuptake = referenceKSuptake; myReferenceRLD = referenceRLD; myExponentSoilMoisture = exponentSoilMoisture; // Link to soil and initialise variables myZoneName = mySoil.Parent.Name; mySoilNH4Available = new double[nLayers]; mySoilNO3Available = new double[nLayers]; NO3 = Apsim.Find(mySoil, "NO3") as ISolute; NH4 = Apsim.Find(mySoil, "NH4") as ISolute; // Initialise root DM, N, depth, and distribution Depth = initialDepth; TargetDistribution = RootDistributionTarget(); double[] iniRootFraction = CurrentRootDistributionTarget(); for (int layer = 0; layer < nLayers; layer++) { Tissue[0].DMLayer[layer] = initialDM * iniRootFraction[layer]; Tissue[0].NamountLayer[layer] = NConcOptimum * Tissue[0].DMLayer[layer]; } }
/// <summary>Constructor, initialise tissues for the roots.</summary> /// <param name="zone">The zone the roots belong in.</param> /// <param name="initialDM">Initial dry matter weight</param> /// <param name="initialDepth">Initial root depth</param> /// <param name="minLiveDM">The minimum biomass for this organ</param> /// <param name="waterAvailableMethod">Method to compute water available</param> /// <param name="nitrogenAvailableMethod">Method to compute N available</param> /// <param name="kNH4">Parameter to compute NN4 available, default method</param> /// <param name="kNO3">Parameter to compute NO3 available, default method</param> /// <param name="maxNUptake">Parameter to compute N uptake, default method</param> /// <param name="kuNH4">Parameter to compute NH4 available, alternative method</param> /// <param name="kuNO3">Parameter to compute NO3 available, alternative method</param> /// <param name="referenceKSuptake">Parameter to compute available water, conductivity</param> /// <param name="referenceRLD">Parameter to compute available water, roots</param> /// <param name="exponentSoilMoisture">Parameter to compute available water</param> public void Initialise(Zone zone, double initialDM, double initialDepth, double minLiveDM, PastureSpecies.PlantAvailableWaterMethod waterAvailableMethod, PastureSpecies.PlantAvailableNitrogenMethod nitrogenAvailableMethod, double kNH4, double kNO3, double maxNUptake, double kuNH4, double kuNO3, double referenceKSuptake, double referenceRLD, double exponentSoilMoisture) { mySoil = Apsim.Find(zone, typeof(Soil)) as Soil; if (mySoil == null) { throw new Exception($"Cannot find soil in zone {zone.Name}"); } SoilNitrogen = Apsim.Find(zone, typeof(INutrient)) as INutrient; if (SoilNitrogen == null) { throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}"); } NO3 = Apsim.Find(zone, "NO3") as ISolute; if (NO3 == null) { throw new Exception($"Cannot find NO3 solute in zone {zone.Name}"); } NH4 = Apsim.Find(zone, "NH4") as ISolute; if (NH4 == null) { throw new Exception($"Cannot find NH4 solute in zone {zone.Name}"); } // save the parameters for this organ nLayers = mySoil.Thickness.Length; MinimumLiveDM = minLiveDM; myWaterAvailableMethod = waterAvailableMethod; myNitrogenAvailableMethod = nitrogenAvailableMethod; myKNO3 = kNO3; myKNH4 = kNH4; myMaximumNUptake = maxNUptake; myKuNH4 = kuNH4; myKuNO3 = kuNO3; myReferenceKSuptake = referenceKSuptake; myReferenceRLD = referenceRLD; myExponentSoilMoisture = exponentSoilMoisture; // Link to soil and initialise variables myZoneName = mySoil.Parent.Name; mySoilNH4Available = new double[nLayers]; mySoilNO3Available = new double[nLayers]; // Initialise root DM, N, depth, and distribution Depth = initialDepth; TargetDistribution = RootDistributionTarget(); double[] initialDMByLayer = MathUtilities.Multiply_Value(CurrentRootDistributionTarget(), initialDM); double[] initialNByLayer = MathUtilities.Multiply_Value(initialDMByLayer, NConcOptimum); // Initialise the live tissue. Tissue[0].Initialise(initialDMByLayer, initialNByLayer); Tissue[1].Initialise(null, null); }
/// <summary>Constructor</summary> public OutputLayers() { NO3Solute = Apsim.Find(this, "NO3") as ISolute; NH4Solute = Apsim.Find(this, "NH4") as ISolute; UreaSolute = Apsim.Find(this, "Urea") as ISolute; }
/// <summary>Constructor</summary> public OutputLayers() { NO3Solute = this.FindInScope("NO3") as ISolute; NH4Solute = this.FindInScope("NH4") as ISolute; UreaSolute = this.FindInScope("Urea") as ISolute; }
private void OnSimulationCommencing(object sender, EventArgs e) { sourceSolute = Apsim.FindAll(this, typeof(ISolute)).Find(s => s.Name == Parent.Name) as ISolute; destinationSolute = Apsim.FindAll(this, typeof(ISolute)).Find(s => s.Name == destinationName) as ISolute; }