Esempio n. 1
0
        public double ApplyResources_ByDate(double TotalNApplied, ref double TotalWApplied)
        {
            double NApplied      = 0;
            double NNIThreshold  = Run.ManagementDef.NNIThreshold;
            double NNIMultiplier = Run.ManagementDef.NNIMultiplier;

            var dateApp = Run.ManagementDef[CurrentDate];

            ///<Behnam (2015.10.20)>
            ///<Comment>To enable using total N fertisation and application shares at each event.
            ///<Behnam (2016.01.11)>
            ///Also a trend is applied, if applicable.</Comment>

            if (dateApp != null)
            {
                //if (!isUnlimitedWater) Soil_.Irrigate(dateApp.Water);
                Soil_.Irrigate(dateApp.Water);
                TotalWApplied += dateApp.Water;

                if (!isUnlimitedNitrogen)
                {
                    if (Run.ManagementDef.IsTotalNitrogen)
                    {
                        NApplied = NFertChange * dateApp.Nitrogen * Run.ManagementDef.TotalNApplication / 100;
                    }
                    else
                    {
                        NApplied = NFertChange * dateApp.Nitrogen;
                    }

                    ///<Comment>If NNI is to be used, the amount of N application is calculated by CalcNFertilisation</Comment>
                    if (Run.ManagementDef.IsNNIUsed && !isUnlimitedNitrogen)
                    {
                        NApplied = CalcNFertilisation(NNIThreshold, NNIMultiplier, TotalNApplied, NApplied);
                    }

                    /// Behnam (2016.05.14): Adding WaterAppWithNApp mm of water for each N application, if needed.
                    if (NApplied > 0 && TotalWApplied < WaterAppWithNApp * Run.MMwaterToGwater)
                    {
                        var WaterNeeded = WaterAppWithNApp * Run.MMwaterToGwater - TotalWApplied;
                        Soil_.Irrigate(WaterNeeded);
                        TotalWApplied += WaterNeeded;
                    }
                    NAdded = NApplied;
                    Soil_.Fertilize(NApplied);
                }
                TotalNApplied += NApplied;
            }
            return(TotalNApplied);
            ///</Behnam>
        }
Esempio n. 2
0
        public double ApplyResources_ByGrowthStage(double TotalNApplied, ref double TotalWApplied)
        {
            var gs = 0;

            foreach (var growthStageApp in Run.ManagementDef.GrowthStageApplications)
            {
                ///<Behnam (2015.10.22)>
                ///<Comment>
                ///Keep in mind, N and irrigation are triggered at least one day after the specified
                ///growth stage, but as they are applied at the begining of the simulation of each day,
                ///it is like they are applied one day earlier.
                ///</Comment>

                double NApplied      = 0;
                double NNIThreshold  = Run.ManagementDef.NNIThreshold;
                double NNIMultiplier = Run.ManagementDef.NNIMultiplier;

                gs += 1;
                var dateMoment = Run.CurrentUniverse.Crop_.getDateOfStage(growthStageApp.GrowthStage);

                ///<Comment>Don't apply irrigation if this irrigation event has already been triggered</Comment>
                if (PrevAppliedStagesIrr == gs)
                {
                    if (dateMoment.HasValue && dateMoment.Value.AddDays(1) == CurrentDate)
                    {
                        //if (!isUnlimitedWater) Soil_.Irrigate(growthStageApp.Water);
                        Soil_.Irrigate(growthStageApp.Water);
                        PrevAppliedStagesIrr += 1;
                        TotalWApplied        += growthStageApp.Water;
                    }
                }

                ///<Comment>Don't apply N if this N application event has already been triggered</Comment>
                if (PrevAppliedStagesN == gs)
                {
                    if (dateMoment.HasValue)
                    {
                        bool apply = true;
                        if (Run.ManagementDef.IsCheckPcpN)
                        {
                            ///<Comment>Check for cumulative precipitation over CheckDaysPcpN coming days, if applicable</Comment>
                            double cumpcp = Weather_.CumRainMM(CurrentDate, Run.ManagementDef.CheckDaysPcpN, false);

                            ///<Comment>Apply N if precipitation criterion is met or MaxPostponeN is reached</Comment>
                            apply = (cumpcp >= Run.ManagementDef.CumPcpThrN ||
                                     dateMoment.Value.AddDays(Run.ManagementDef.MaxPostponeN) <= CurrentDate);
                        }

                        if (apply)
                        {
                            if (!isUnlimitedNitrogen)
                            {
                                ///<Comment>To enable using total N fertisation and application shares at each event</Comment>
                                if (Run.ManagementDef.IsTotalNitrogen)
                                {
                                    NApplied = NFertChange * growthStageApp.Nitrogen * Run.ManagementDef.TotalNApplication / 100;
                                }
                                else
                                {
                                    NApplied = NFertChange * growthStageApp.Nitrogen;
                                }

                                ///<Comment>If NNI is to be used, the amount of N application is calculated by CalcNFertilisation</Comment>
                                if (Run.ManagementDef.IsNNIUsed && !isUnlimitedNitrogen)
                                {
                                    NApplied = CalcNFertilisation(NNIThreshold, NNIMultiplier, TotalNApplied, NApplied);
                                }

                                /// Behnam (2016.05.14): Adding WaterAppWithNApp mm of water for each N application, if needed.
                                if (NApplied > 0 && TotalWApplied < WaterAppWithNApp * Run.MMwaterToGwater)
                                {
                                    var WaterNeeded = WaterAppWithNApp * Run.MMwaterToGwater - TotalWApplied;
                                    Soil_.Irrigate(WaterNeeded);
                                    TotalWApplied += WaterNeeded;
                                }
                                NAdded = NApplied;
                                Soil_.Fertilize(NApplied);
                            }
                            TotalNApplied      += NApplied;
                            PrevAppliedStagesN += 1;
                        }
                    }
                }
            }
            return(TotalNApplied);
            ///</Behnam>
        }