private void StoreWaterVariablesForNitrogenUptake(ZoneWaterAndN zoneWater)
        {
            ZoneState myZone = root.Zones.Find(z => z.Name == zoneWater.Zone.Name);

            if (myZone != null)
            {
                var soilPhysical = myZone.Soil.FindChild <Soils.IPhysical>();
                var waterBalance = myZone.Soil.FindChild <ISoilWater>();

                //store Water variables for N Uptake calculation
                //Old sorghum doesn't do actualUptake of Water until end of day
                myZone.StartWater           = new double[soilPhysical.Thickness.Length];
                myZone.AvailableSW          = new double[soilPhysical.Thickness.Length];
                myZone.PotentialAvailableSW = new double[soilPhysical.Thickness.Length];
                myZone.Supply = new double[soilPhysical.Thickness.Length];

                var soilCrop = Soil.FindDescendant <SoilCrop>(plant.Name + "Soil");
                if (soilCrop == null)
                {
                    throw new Exception($"Cannot find a soil crop parameterisation called {plant.Name + "Soil"}");
                }

                double[] kl = soilCrop.KL;

                double[] llDep = MathUtilities.Multiply(soilCrop.LL, soilPhysical.Thickness);

                if (root.Depth != myZone.Depth)
                {
                    myZone.Depth += 0; // wtf??
                }
                var currentLayer = SoilUtilities.LayerIndexOfDepth(myZone.Physical.Thickness, myZone.Depth);
                for (int layer = 0; layer <= currentLayer; ++layer)
                {
                    myZone.StartWater[layer] = waterBalance.SWmm[layer];

                    myZone.AvailableSW[layer]          = Math.Max(waterBalance.SWmm[layer] - llDep[layer] * myZone.LLModifier[layer], 0) * myZone.RootProportions[layer];
                    myZone.PotentialAvailableSW[layer] = Math.Max(soilPhysical.DULmm[layer] - llDep[layer] * myZone.LLModifier[layer], 0) * myZone.RootProportions[layer];

                    var proportion = myZone.RootProportions[layer];
                    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);
            }
        }
Example #2
0
        private void OnSimulationCommencing(object sender, EventArgs e)
        {
            Uptakes = new List <ZoneWaterAndN>();
            EP      = 0;

            soilCrop = Soil.FindDescendant <SoilCrop>(Name + "Soil");
            if (soilCrop == null)
            {
                throw new Exception($"Cannot find a soil crop parameterisation called {Name}Soil");
            }
        }