private void StoreWaterVariablesForNitrogenUptake(ZoneWaterAndN zoneWater) { ZoneState myZone = root.Zones.Find(z => z.Name == zoneWater.Zone.Name); if (myZone != null) { //store Water variables for N Uptake calculation //Old sorghum doesn't do actualUptake of Water until end of day myZone.StartWater = new double[myZone.soil.Thickness.Length]; myZone.AvailableSW = new double[myZone.soil.Thickness.Length]; myZone.PotentialAvailableSW = new double[myZone.soil.Thickness.Length]; myZone.Supply = new double[myZone.soil.Thickness.Length]; var soilCrop = Soil.Crop(plant.Name); double[] kl = soilCrop.KL; double[] llDep = MathUtilities.Multiply(soilCrop.LL, myZone.soil.Thickness); if (root.Depth != myZone.Depth) { myZone.Depth += 0; // wtf?? } var currentLayer = myZone.soil.LayerIndexOfDepth(myZone.Depth); var currentLayerProportion = myZone.soil.ProportionThroughLayer(currentLayer, myZone.Depth); for (int layer = 0; layer <= currentLayer; ++layer) { myZone.StartWater[layer] = myZone.soil.Water[layer]; myZone.AvailableSW[layer] = Math.Max(myZone.soil.Water[layer] - llDep[layer], 0); myZone.PotentialAvailableSW[layer] = myZone.soil.DULmm[layer] - llDep[layer]; if (layer == currentLayer) { myZone.AvailableSW[layer] *= currentLayerProportion; myZone.PotentialAvailableSW[layer] *= currentLayerProportion; } var proportion = root.rootProportionInLayer(layer, myZone); myZone.Supply[layer] = Math.Max(myZone.AvailableSW[layer] * kl[layer] * proportion, 0.0); } var totalAvail = myZone.AvailableSW.Sum(); var totalAvailPot = myZone.PotentialAvailableSW.Sum(); var totalSupply = myZone.Supply.Sum(); WatSupply = totalSupply; // Set reporting variables. //Avail = myZone.AvailableSW; //PotAvail = myZone.PotentialAvailableSW; //used for SWDef PhenologyStress table lookup SWAvailRatio = MathUtilities.Bound(MathUtilities.Divide(totalAvail, totalAvailPot, 1.0), 0.0, 10.0); //used for SWDef ExpansionStress table lookup SDRatio = MathUtilities.Bound(MathUtilities.Divide(totalSupply, WDemand, 1.0), 0.0, 10); //used for SwDefPhoto Stress //PhotoStress = MathUtilities.Bound(MathUtilities.Divide(totalSupply, WDemand, 1.0), 0.0, 1.0); } }
/// <summary>Calculate the potential sw uptake for today</summary> /// <param name="soilstate"></param> /// <returns>list of uptakes</returns> /// <exception cref="ApsimXException">Could not find root zone in Zone + this.Parent.Name + for SimpleTree</exception> public List <ZoneWaterAndN> GetWaterUptakeEstimates(SoilState soilstate) { ZoneWaterAndN MyZone = new ZoneWaterAndN(this.Parent as Zone); foreach (ZoneWaterAndN Z in soilstate.Zones) { if (Z.Zone.Name == this.Parent.Name) { MyZone = Z; } } double[] PotSWUptake = new double[Soil.LL15.Length]; SWUptake = new double[Soil.LL15.Length]; SoilCrop soilCrop = Soil.Crop(this.Name) as SoilCrop; for (int j = 0; j < Soil.LL15mm.Length; j++) { PotSWUptake[j] = Math.Max(0.0, RootProportion(j, RootDepth) * soilCrop.KL[j] * (MyZone.Water[j] - Soil.LL15mm[j])); } double TotPotSWUptake = MathUtilities.Sum(PotSWUptake); for (int j = 0; j < Soil.LL15mm.Length; j++) { SWUptake[j] = PotSWUptake[j] * Math.Min(1.0, PotentialEP / TotPotSWUptake); } List <ZoneWaterAndN> Uptakes = new List <ZoneWaterAndN>(); ZoneWaterAndN Uptake = new ZoneWaterAndN(this.Parent as Zone); Uptake.Water = SWUptake; Uptake.NO3N = new double[SWUptake.Length]; Uptake.NH4N = new double[SWUptake.Length]; Uptake.NH4N = new double[SWUptake.Length]; Uptake.PlantAvailableNO3N = new double[SWUptake.Length]; Uptake.PlantAvailableNH4N = new double[SWUptake.Length]; Uptakes.Add(Uptake); return(Uptakes); }