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); }
private void OnWFUpdatePasture(object sender, EventArgs e) { //TODO: Get pasture growth from pasture model or GRASP output // // temporary pasture input for testing // GrazeFoodStorePool newPasture = new GrazeFoodStorePool(); newPasture.Age = 0; if (Clock.Today.Month >= 11 ^ Clock.Today.Month <= 3) { newPasture.Set(500 * Area); newPasture.DMD = this.LinkedNativeFoodType.DMD; newPasture.DryMatter = this.LinkedNativeFoodType.DryMatter; newPasture.Nitrogen = this.LinkedNativeFoodType.Nitrogen; this.LinkedNativeFoodType.Add(newPasture); } // store total pasture at start of month PastureAtStartOfMonth = this.LinkedNativeFoodType.Amount; }
private void SetupStartingPasturePools(double StartingGrowth) { // Initial biomass double amountToAdd = Area * StartingGrowth; if (amountToAdd <= 0) { return; } // Set up pasture pools to start run based on month and user defined pasture properties // Locates the previous five months where growth occurred (Nov-Mar) and applies decomposition to current month // This months growth will not be included. int month = Clock.Today.Month; int monthCount = 0; int includedMonthCount = 0; double propBiomass = 1.0; double currentN = LinkedNativeFoodType.GreenNitrogen; // NABSA changes N by 0.8 for particular months. Not needed here as decay included. double currentDMD = currentN * LinkedNativeFoodType.NToDMDCoefficient + LinkedNativeFoodType.NToDMDIntercept; currentDMD = Math.Max(LinkedNativeFoodType.MinimumDMD, currentDMD); LinkedNativeFoodType.Pools.Clear(); List <GrazeFoodStorePool> newPools = new List <GrazeFoodStorePool>(); while (includedMonthCount < 5) { if (month == 0) { month = 12; } if (month <= 3 | month >= 11) { // add new pool newPools.Add(new GrazeFoodStorePool() { Age = monthCount, Nitrogen = currentN, DMD = currentDMD, StartingAmount = propBiomass }); includedMonthCount++; } propBiomass *= 1 - LinkedNativeFoodType.DetachRate; currentN -= LinkedNativeFoodType.DecayNitrogen; currentN = Math.Max(currentN, LinkedNativeFoodType.MinimumNitrogen); currentDMD *= 1 - LinkedNativeFoodType.DecayDMD; currentDMD = Math.Max(currentDMD, LinkedNativeFoodType.MinimumDMD); monthCount++; month--; } // assign pasture biomass to pools based on proportion of total double total = newPools.Sum(a => a.StartingAmount); foreach (var pool in newPools) { pool.Set(amountToAdd * (pool.StartingAmount / total)); pool.Growth = amountToAdd * (pool.StartingAmount / total); } // Previously: remove this months growth from pool age 0 to keep biomass at approximately setup. // But as updates happen at the end of the month, the fist months biomass is never added so stay with 0 or delete following section // Get this months growth //Get this months pasture data from the pasture data list PastureDataType pasturedata = PastureDataList.Where(a => a.Year == Clock.StartDate.Year && a.Month == Clock.StartDate.Month).FirstOrDefault(); //double growth = ; // GRASPFile.Get(xxxxxxxxx) double thisMonthsGrowth = pasturedata.Growth; if (thisMonthsGrowth > 0) { GrazeFoodStorePool thisMonth = newPools.Where(a => a.Age == 0).FirstOrDefault() as GrazeFoodStorePool; if (thisMonth != null) { thisMonth.Set(Math.Max(0, thisMonth.Amount - thisMonthsGrowth)); } } // Add to pasture. This will add pool to pasture available store. foreach (var pool in newPools) { string reason = "Initialise"; if (newPools.Count() > 1) { reason = "Initialise pool " + pool.Age.ToString(); } LinkedNativeFoodType.Add(pool, this.Name, reason); } }
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); }