Beispiel #1
0
        /// <summary>
        /// General soil arbitration method (water or nutrients) based upon Runge-Kutta method
        /// </summary>
        /// <param name="arbitrationType">Water or Nitrogen</param>
        private void DoArbitration(Estimate.CalcType arbitrationType)
        {
            SoilState InitialSoilState = new SoilState(this.Parent);
            InitialSoilState.Initialise();

            Estimate UptakeEstimate1 = new Estimate(this.Parent, arbitrationType, InitialSoilState);
            Estimate UptakeEstimate2 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate1 * 0.5);
            Estimate UptakeEstimate3 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate2 * 0.5);
            Estimate UptakeEstimate4 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate3);

            List<CropUptakes> UptakesFinal = new List<CropUptakes>();
            foreach (CropUptakes U in UptakeEstimate1.Values)
            {
                CropUptakes CWU = new CropUptakes();
                CWU.Crop = U.Crop;
                foreach (ZoneWaterAndN ZW1 in U.Zones)
                {
                    ZoneWaterAndN NewZ = UptakeEstimate1.UptakeZone(CWU.Crop, ZW1.Name) * (1.0 / 6.0)
                                       + UptakeEstimate2.UptakeZone(CWU.Crop, ZW1.Name) * (1.0 / 3.0)
                                       + UptakeEstimate3.UptakeZone(CWU.Crop, ZW1.Name) * (1.0 / 3.0)
                                       + UptakeEstimate4.UptakeZone(CWU.Crop, ZW1.Name) * (1.0 / 6.0);
                    CWU.Zones.Add(NewZ);
                }

                UptakesFinal.Add(CWU);
            }

            foreach (CropUptakes Uptake in UptakesFinal)
            {
                if (arbitrationType == Estimate.CalcType.Water)
                    Uptake.Crop.SetSWUptake(Uptake.Zones);
                else
                    Uptake.Crop.SetNUptake(Uptake.Zones);
            }
        }
Beispiel #2
0
        /// <summary>Initializes a new instance of the <see cref="Estimate"/> class.</summary>
        /// <param name="parent">The parent model</param>
        /// <param name="Type">The type of estimate</param>
        /// <param name="soilstate">The state of the soil</param>
        /// <param name="uptakeModels">A list of models that do uptake.</param>
        public Estimate(IModel parent, CalcType Type, SoilState soilstate, List <IModel> uptakeModels)
        {
            Values = new List <CropUptakes>();

            Parent = parent;
            foreach (IUptake crop in uptakeModels)
            {
                List <ZoneWaterAndN> uptake;
                if (Type == CalcType.Water)
                {
                    uptake = crop.GetSWUptakes(soilstate);
                }
                else
                {
                    uptake = crop.GetNUptakes(soilstate);
                }

                if (uptake != null)
                {
                    CropUptakes Uptake = new CropUptakes();
                    Uptake.Crop  = crop;
                    Uptake.Zones = uptake;
                    Values.Add(Uptake);
                }
            }
        }
Beispiel #3
0
        /// <summary>Implements the operator *.</summary>
        /// <param name="E">The estimate</param>
        /// <param name="value">The value to multiply the estimate by.</param>
        /// <returns>The resulting estimate</returns>
        public static Estimate operator *(Estimate E, double value)
        {
            Estimate NewE = new Estimate(E.Parent);

            foreach (CropUptakes U in E.Values)
            {
                CropUptakes NewU = new CropUptakes();
                NewE.Values.Add(NewU);
                foreach (ZoneWaterAndN Z in U.Zones)
                {
                    ZoneWaterAndN NewZ = Z * value;
                    NewU.Zones.Add(NewZ);
                }
            }

            return(NewE);
        }
Beispiel #4
0
        /// <summary>
        /// General soil arbitration method (water or nutrients) based upon Runge-Kutta method
        /// </summary>
        /// <param name="arbitrationType">Water or Nitrogen</param>
        private void DoArbitration(Estimate.CalcType arbitrationType)
        {
            SoilState InitialSoilState = new SoilState(this.Parent);

            InitialSoilState.Initialise(zones);

            Estimate UptakeEstimate1 = new Estimate(this.Parent, arbitrationType, InitialSoilState, uptakeModels);
            Estimate UptakeEstimate2 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate1 * 0.5, uptakeModels);
            Estimate UptakeEstimate3 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate2 * 0.5, uptakeModels);
            Estimate UptakeEstimate4 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate3, uptakeModels);

            List <ZoneWaterAndN> listOfZoneUptakes = new List <ZoneWaterAndN>();
            List <CropUptakes>   ActualUptakes     = new List <CropUptakes>();

            foreach (CropUptakes U in UptakeEstimate1.Values)
            {
                CropUptakes CU = new CropUptakes();
                CU.Crop = U.Crop;
                foreach (ZoneWaterAndN ZU in U.Zones)
                {
                    ZoneWaterAndN NewZone = UptakeEstimate1.UptakeZone(CU.Crop, ZU.Zone.Name) * (1.0 / 6.0)
                                            + UptakeEstimate2.UptakeZone(CU.Crop, ZU.Zone.Name) * (1.0 / 3.0)
                                            + UptakeEstimate3.UptakeZone(CU.Crop, ZU.Zone.Name) * (1.0 / 3.0)
                                            + UptakeEstimate4.UptakeZone(CU.Crop, ZU.Zone.Name) * (1.0 / 6.0);
                    CU.Zones.Add(NewZone);
                    listOfZoneUptakes.Add(NewZone);
                }

                ActualUptakes.Add(CU);
            }

            ScaleWaterAndNIfNecessary(InitialSoilState.Zones, listOfZoneUptakes);

            foreach (CropUptakes Uptake in ActualUptakes)
            {
                if (arbitrationType == Estimate.CalcType.Water)
                {
                    Uptake.Crop.SetActualWaterUptake(Uptake.Zones);
                }
                else
                {
                    Uptake.Crop.SetActualNitrogenUptakes(Uptake.Zones);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// General soil arbitration method (water or nutrients) based upon Runge-Kutta method
        /// </summary>
        /// <param name="arbitrationType">Water or Nitrogen</param>
        private void DoArbitration(Estimate.CalcType arbitrationType)
        {
            SoilState InitialSoilState = new SoilState(this.Parent);

            InitialSoilState.Initialise(zones);

            Estimate UptakeEstimate1 = new Estimate(this.Parent, arbitrationType, InitialSoilState, uptakeModels);
            Estimate UptakeEstimate2 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate1 * 0.5, uptakeModels);
            Estimate UptakeEstimate3 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate2 * 0.5, uptakeModels);
            Estimate UptakeEstimate4 = new Estimate(this.Parent, arbitrationType, InitialSoilState - UptakeEstimate3, uptakeModels);

            List <ZoneWaterAndN> listOfZoneWaterAndNs = new List <ZoneWaterAndN>();
            List <CropUptakes>   UptakesFinal         = new List <CropUptakes>();

            foreach (CropUptakes U in UptakeEstimate1.Values)
            {
                CropUptakes CWU = new CropUptakes();
                CWU.Crop = U.Crop;
                foreach (ZoneWaterAndN ZW1 in U.Zones)
                {
                    ZoneWaterAndN NewZ = UptakeEstimate1.UptakeZone(CWU.Crop, ZW1.Zone.Name) * (1.0 / 6.0)
                                         + UptakeEstimate2.UptakeZone(CWU.Crop, ZW1.Zone.Name) * (1.0 / 3.0)
                                         + UptakeEstimate3.UptakeZone(CWU.Crop, ZW1.Zone.Name) * (1.0 / 3.0)
                                         + UptakeEstimate4.UptakeZone(CWU.Crop, ZW1.Zone.Name) * (1.0 / 6.0);
                    CWU.Zones.Add(NewZ);
                    listOfZoneWaterAndNs.Add(NewZ);
                }

                UptakesFinal.Add(CWU);
            }

            ScaleWaterAndNIfNecessary(InitialSoilState.Zones, listOfZoneWaterAndNs);

            foreach (CropUptakes Uptake in UptakesFinal)
            {
                if (arbitrationType == Estimate.CalcType.Water)
                {
                    Uptake.Crop.SetSWUptake(Uptake.Zones);
                }
                else
                {
                    Uptake.Crop.SetNUptake(Uptake.Zones);
                }
            }
        }
Beispiel #6
0
        /// <summary>Initializes a new instance of the <see cref="Estimate"/> class.</summary>
        /// <param name="parent">The parent model</param>
        /// <param name="Type">The type of estimate</param>
        /// <param name="soilstate">The state of the soil</param>
        /// <param name="uptakeModels">A list of models that do uptake.</param>
        public Estimate(IModel parent, CalcType Type, SoilState soilstate, List<IModel> uptakeModels)
        {
            Values = new List<CropUptakes>();

            Parent = parent;
            foreach (IUptake crop in uptakeModels)
            {
                List<ZoneWaterAndN> uptake;
                if (Type == CalcType.Water)
                    uptake = crop.GetSWUptakes(soilstate);
                else
                    uptake = crop.GetNUptakes(soilstate);

                if (uptake != null)
                {
                    CropUptakes Uptake = new CropUptakes();
                    Uptake.Crop = crop;
                    Uptake.Zones = uptake;
                    Values.Add(Uptake);
                }
            }
        }
Beispiel #7
0
        /// <summary>Implements the operator *.</summary>
        /// <param name="E">The estimate</param>
        /// <param name="value">The value to multiply the estimate by.</param>
        /// <returns>The resulting estimate</returns>
        public static Estimate operator *(Estimate E, double value)
        {
            Estimate NewE = new Estimate(E.Parent);
            foreach (CropUptakes U in E.Values)
            {
                CropUptakes NewU = new CropUptakes();
                NewE.Values.Add(NewU);
                foreach (ZoneWaterAndN Z in U.Zones)
                {
                    ZoneWaterAndN NewZ = Z * value;
                    NewU.Zones.Add(NewZ);
                }
            }

            return NewE;
        }