Example #1
0
        private void OnCLEMUpdatePasture(object sender, EventArgs e)
        {
            this.Status = ActivityStatus.Ignored;
            if (PastureDataList != null)
            {
                this.Status = ActivityStatus.NotNeeded;
                double growth = 0;

                //Get this months pasture data from the pasture data list
                PastureDataType pasturedata = PastureDataList.Where(a => a.Year == Clock.Today.Year && a.Month == Clock.Today.Month).FirstOrDefault();

                growth = pasturedata.Growth;
                //TODO: check units from input files.
                // convert from kg/ha to kg/area unit
                growth *= unitsOfArea2Ha;

                LinkedNativeFoodType.CurrentEcologicalIndicators.Rainfall      += pasturedata.Rainfall;
                LinkedNativeFoodType.CurrentEcologicalIndicators.Erosion       += pasturedata.SoilLoss;
                LinkedNativeFoodType.CurrentEcologicalIndicators.Runoff        += pasturedata.Runoff;
                LinkedNativeFoodType.CurrentEcologicalIndicators.Cover         += pasturedata.Cover;
                LinkedNativeFoodType.CurrentEcologicalIndicators.TreeBasalArea += pasturedata.TreeBA;

                if (growth > 0)
                {
                    this.Status = ActivityStatus.Success;
                    GrazeFoodStorePool newPasture = new GrazeFoodStorePool
                    {
                        Age = 0
                    };
                    newPasture.Set(growth * Area);
                    newPasture.Nitrogen = this.LinkedNativeFoodType.GreenNitrogen;
                    newPasture.DMD      = newPasture.Nitrogen * LinkedNativeFoodType.NToDMDCoefficient + LinkedNativeFoodType.NToDMDIntercept;
                    newPasture.DMD      = Math.Min(100, Math.Max(LinkedNativeFoodType.MinimumDMD, newPasture.DMD));
                    newPasture.Growth   = newPasture.Amount;
                    this.LinkedNativeFoodType.Add(newPasture, this, "Growth");
                }
            }

            // report activity performed.
            ActivityPerformedEventArgs activitye = new ActivityPerformedEventArgs
            {
                Activity = new BlankActivity()
                {
                    Status = ZoneCLEM.IsEcologicalIndicatorsCalculationMonth()? ActivityStatus.Calculation: ActivityStatus.Success,
                    Name   = this.Name
                }
            };

            activitye.Activity.SetGuID(this.UniqueID);
            this.OnActivityPerformed(activitye);
        }
        private void OnCLEMUpdatePasture(object sender, EventArgs e)
        {
            if (PastureDataList != null)
            {
                double growth = 0;

                // method is performed on last day of month but needs to work with next month's details
                int year  = Clock.Today.AddDays(1).Year;
                int month = Clock.Today.AddDays(1).Month;

                //Get this months pasture data from the pasture data list
                PastureDataType pasturedata = PastureDataList.Where(a => a.Year == year && a.Month == month).FirstOrDefault();

                growth = pasturedata.Growth;
                //TODO: check units from input files.
                // convert from kg/ha to kg/area unit
                growth = growth * unitsOfArea2Ha;

                if (growth > 0)
                {
                    GrazeFoodStorePool newPasture = new GrazeFoodStorePool();
                    newPasture.Age = 0;
                    newPasture.Set(growth * Area);
                    newPasture.Nitrogen = this.LinkedNativeFoodType.GreenNitrogen;
                    newPasture.DMD      = newPasture.Nitrogen * LinkedNativeFoodType.NToDMDCoefficient + LinkedNativeFoodType.NToDMDIntercept;
                    newPasture.DMD      = Math.Min(100, Math.Max(LinkedNativeFoodType.MinimumDMD, newPasture.DMD));
                    this.LinkedNativeFoodType.Add(newPasture, this.Name, "Growth");
                }
            }
            else
            {
                throw new Exception("No pasture data");
            }

            // report activity performed.
            ActivityPerformedEventArgs activitye = new ActivityPerformedEventArgs
            {
                Activity = new BlankActivity()
                {
                    Status = ZoneCLEM.IsEcologicalIndicatorsCalculationMonth()? ActivityStatus.Calculation: ActivityStatus.Success,
                    Name   = this.Name
                }
            };

            this.OnActivityPerformed(activitye);
        }
Example #3
0
        private void OnCLEMEndOfTimeStep(object sender, EventArgs e)
        {
            // fire all activity performed triggers at end of time step
            foreach (CLEMActivityBase child in Children.Where(a => a.GetType().IsSubclassOf(typeof(CLEMActivityBase))))
            {
                child.ReportAllAllActivitiesPerformed();
            }

            // add timestep activity for reporting
            ActivityPerformedEventArgs ea = new ActivityPerformedEventArgs()
            {
                Activity = TimeStep
            };

            LastActivityPerformed = TimeStep;
            OnActivityPerformed(ea);
        }
Example #4
0
        private void OnCLEMEndOfTimeStep(object sender, EventArgs e)
        {
            // fire all activity performed triggers at end of time step
            foreach (CLEMActivityBase child in Children.Where(a => a.GetType().IsSubclassOf(typeof(CLEMActivityBase))))
            {
                if (child.Enabled)
                {
                    child.ReportAllAllActivitiesPerformed();
                }
            }

            // report all timers that were due this time step
            foreach (IActivityTimer timer in Apsim.ChildrenRecursively(this, typeof(IActivityTimer)))
            {
                if (timer.ActivityDue)
                {
                    // report activity performed.
                    ActivityPerformedEventArgs timerActivity = new ActivityPerformedEventArgs
                    {
                        Activity = new BlankActivity()
                        {
                            Status = ActivityStatus.Timer,
                            Name   = (timer as IModel).Name
                        }
                    };
                    timerActivity.Activity.SetGuID((timer as CLEMModel).UniqueID);
                    timer.OnActivityPerformed(timerActivity);
                }
            }

            // add timestep activity for reporting
            ActivityPerformedEventArgs ea = new ActivityPerformedEventArgs()
            {
                Activity = timeStep
            };

            LastActivityPerformed = timeStep;
            OnActivityPerformed(ea);
        }
Example #5
0
        private void OnCLEMEndOfTimeStep(object sender, EventArgs e)
        {
            // fire all activity performed triggers at end of time step
            foreach (CLEMActivityBase child in FindAllChildren <CLEMActivityBase>())
            {
                child.ReportAllAllActivitiesPerformed();
            }

            // report all timers that were due this time step
            foreach (IActivityTimer timer in this.FindAllDescendants <IActivityTimer>())
            {
                if (timer.ActivityDue)
                {
                    // report activity performed.
                    ActivityPerformedEventArgs timerActivity = new ActivityPerformedEventArgs
                    {
                        Activity = new BlankActivity()
                        {
                            Status = ActivityStatus.Timer,
                            Name   = (timer as IModel).Name
                        }
                    };
                    timerActivity.Activity.SetGuID((timer as CLEMModel).UniqueID);
                    timer.OnActivityPerformed(timerActivity);
                }
            }

            // add timestep activity for reporting
            ActivityPerformedEventArgs ea = new ActivityPerformedEventArgs()
            {
                Activity = timeStep
            };

            LastActivityPerformed = timeStep;
            OnActivityPerformed(ea);
        }
Example #6
0
        private void OnCLEMUpdatePasture(object sender, EventArgs e)
        {
            this.Status = ActivityStatus.Ignored;
            if (PastureDataList != null)
            {
                this.Status = ActivityStatus.NotNeeded;
                double growth = 0;

                //// method is performed on last day of month but needs to work with next month's details
                //int year = Clock.Today.AddDays(1).Year;
                //int month = Clock.Today.AddDays(1).Month;

                int year  = Clock.Today.Year;
                int month = Clock.Today.Month;

                //Get this months pasture data from the pasture data list
                PastureDataType pasturedata = PastureDataList.Where(a => a.Year == year && a.Month == month).FirstOrDefault();

                growth = pasturedata.Growth;
                //TODO: check units from input files.
                // convert from kg/ha to kg/area unit
                growth *= unitsOfArea2Ha;

                LinkedNativeFoodType.CurrentEcologicalIndicators.Rainfall      += pasturedata.Rainfall;
                LinkedNativeFoodType.CurrentEcologicalIndicators.Erosion       += pasturedata.SoilLoss;
                LinkedNativeFoodType.CurrentEcologicalIndicators.Runoff        += pasturedata.Runoff;
                LinkedNativeFoodType.CurrentEcologicalIndicators.Cover         += pasturedata.Cover;
                LinkedNativeFoodType.CurrentEcologicalIndicators.TreeBasalArea += pasturedata.TreeBA;

                if (growth > 0)
                {
                    this.Status = ActivityStatus.Success;
                    GrazeFoodStorePool newPasture = new GrazeFoodStorePool
                    {
                        Age = 0
                    };
                    newPasture.Set(growth * Area);
                    newPasture.Growth   = growth * Area;
                    newPasture.Nitrogen = this.LinkedNativeFoodType.GreenNitrogen;
                    newPasture.DMD      = newPasture.Nitrogen * LinkedNativeFoodType.NToDMDCoefficient + LinkedNativeFoodType.NToDMDIntercept;
                    newPasture.DMD      = Math.Min(100, Math.Max(LinkedNativeFoodType.MinimumDMD, newPasture.DMD));
                    this.LinkedNativeFoodType.Add(newPasture, this, "Growth");
                }
            }
            else
            {
                this.Status = ActivityStatus.Critical;
                throw new Exception("No pasture data is available for [a=" + this.Name + "]\nCheck that data is available for specified land id and climate region id etc. ");
            }

            // report activity performed.
            ActivityPerformedEventArgs activitye = new ActivityPerformedEventArgs
            {
                Activity = new BlankActivity()
                {
                    Status = ZoneCLEM.IsEcologicalIndicatorsCalculationMonth()? ActivityStatus.Calculation: ActivityStatus.Success,
                    Name   = this.Name
                }
            };

            activitye.Activity.SetGuID(this.UniqueID);
            this.OnActivityPerformed(activitye);
        }
        private void PutPastureInStore()
        {
            AmountHarvested           = 0;
            AmountAvailableForHarvest = 0;
            List <Ruminant> herd = new List <Ruminant>();

            if (this.TimingOK)
            {
                // determine amount to be cut and carried
                if (CutStyle != RuminantFeedActivityTypes.SpecifiedDailyAmount)
                {
                    herd = CurrentHerd(false);
                }
                switch (CutStyle)
                {
                case RuminantFeedActivityTypes.SpecifiedDailyAmount:
                    AmountHarvested += Supply * 30.4;
                    break;

                case RuminantFeedActivityTypes.ProportionOfWeight:
                    foreach (Ruminant ind in herd)
                    {
                        AmountHarvested += Supply * ind.Weight * 30.4;
                    }
                    break;

                case RuminantFeedActivityTypes.ProportionOfPotentialIntake:
                    foreach (Ruminant ind in herd)
                    {
                        AmountHarvested += Supply * ind.PotentialIntake;
                    }
                    break;

                case RuminantFeedActivityTypes.ProportionOfRemainingIntakeRequired:
                    foreach (Ruminant ind in herd)
                    {
                        AmountHarvested += Supply * (ind.PotentialIntake - ind.Intake);
                    }
                    break;

                default:
                    throw new Exception(String.Format("FeedActivityType {0} is not supported in {1}", CutStyle, this.Name));
                }

                AmountAvailableForHarvest = AmountHarvested;
                // reduce amount by limiter if present.
                if (limiter != null)
                {
                    double canBeCarried = limiter.GetAmountAvailable(Clock.Today.Month);
                    AmountHarvested = Math.Max(AmountHarvested, canBeCarried);
                    limiter.AddWeightCarried(AmountHarvested);
                }

                double labourlimiter = 1.0;


                AmountHarvested *= labourlimiter;

                if (AmountHarvested > 0)
                {
                    FoodResourcePacket packet = new FoodResourcePacket()
                    {
                        Amount   = AmountHarvested,
                        PercentN = pasture.Nitrogen,
                        DMD      = pasture.EstimateDMD(pasture.Nitrogen)
                    };

                    // take resource
                    ResourceRequest request = new ResourceRequest()
                    {
                        ActivityModel     = this,
                        AdditionalDetails = this,
                        Category          = "Cut and carry",
                        Required          = AmountHarvested,
                        Resource          = pasture
                    };
                    pasture.Remove(request);

                    foodstore.Add(packet, this, "", "Cut and carry");
                }
                SetStatusSuccess();
            }
            // report activity performed.
            ActivityPerformedEventArgs activitye = new ActivityPerformedEventArgs
            {
                Activity = this
            };

            this.OnActivityPerformed(activitye);
        }
Example #8
0
        private void OnCLEMDoCutAndCarry(object sender, EventArgs e)
        {
            // cut and carry event to ensure this is determined before breeding event

            // calculate whether activity is needed this time step (IndividualsToBreed contains breeders)
            int numberNeeded = 0;

            IndividualsToBreed = null;

            int breedingSpreadMonths = 2;

            // get all breeders currently in the population
            // TODO: remove oftype when sex determination fixed
            var females = controlledMatingParent.CurrentHerd(true).OfType <RuminantFemale>();

            var breedersList = females.Where(r => r.IsBreeder);

            double tooOldToMate = double.PositiveInfinity;

            if (controlledMatingParent != null)
            {
                tooOldToMate = controlledMatingParent.MaximumAgeMating;
            }

            var breedersNotTooOldToMate = breedersList.Where(a => a.Age <= tooOldToMate);

            if (!breedersNotTooOldToMate.Any())
            {
                return;
            }

            // this needs to be calculated here at this time with current herd size
            // this count excludes those too old to be mated from breed param settings
            int maxBreedersPerCycle = Math.Max(1, Convert.ToInt32(Math.Ceiling((double)breedersNotTooOldToMate.Count() / milkingsPerConceptionsCycle)));

            // get females currently lactating
            var lactatingList = females.Where(f => f.IsLactating);

            if (lactatingList.Any() && lactatingList.Max(a => a.Age - a.AgeAtLastBirth) < startBreedCycleGestationOffsett)
            {
                // the max lactation period of lactating females is less than the time to start breeding for future cycle
                // return with no individuals in the IndividualsToBreed list
                return;
            }

            // get breeders currently pregnant
            var pregnantList = females.Where(f => f.IsPregnant);

            // get individuals in first lactation cycle of gestation
            double lactationCyclesInGestation = Math.Round((double)ShortenLactationMonths / pregnancyDuration, 2);

            var firstCycleList = pregnantList.Where(a => a.Age - a.AgeAtLastConception <= lactationCyclesInGestation).ToList();

            if (firstCycleList.Count > 0 && (firstCycleList.Count < maxBreedersPerCycle & firstCycleList.Max(a => a.Age - a.AgeAtLastConception) <= breedingSpreadMonths))
            {
                // if where less than the spread months from the max pregnancy found
                numberNeeded = maxBreedersPerCycle - firstCycleList.Count;
            }

            if (numberNeeded > 0)
            {
                // return the number needed of breeders able to mate in this timestep
                IndividualsToBreed = breedersNotTooOldToMate.Where(a => a.IsAbleToBreed).Take(numberNeeded);

                // report activity performed details.
                ActivityPerformedEventArgs activitye = new ActivityPerformedEventArgs
                {
                    Activity = new BlankActivity()
                    {
                        Status = ActivityStatus.Timer,
                        Name   = this.Name,
                    }
                };
                activitye.Activity.SetGuID(this.UniqueID);
                this.OnActivityPerformed(activitye);
            }
        }