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; Cover = pasturedata.Cover; 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 soil 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 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 OnCLEMAgeResources(object sender, EventArgs e) { if (DecayNitrogen != 0 | DecayDMD > 0) { // decay N and DMD of pools and age by 1 month foreach (var pool in Pools) { // N is a loss of N% (x = x -loss) pool.Nitrogen = Math.Max(pool.Nitrogen - DecayNitrogen, MinimumNitrogen); // DMD is a proportional loss (x = x*(1-proploss)) pool.DMD = Math.Max(pool.DMD * (1 - DecayDMD), MinimumDMD); if (pool.Age < 12) { pool.Age++; } } // remove all pools with less than 10g of food Pools.RemoveAll(a => a.Amount < 0.01); } if (ZoneCLEM.IsEcologicalIndicatorsCalculationMonth()) { OnEcologicalIndicatorsCalculated(new EcolIndicatorsEventArgs() { Indicators = CurrentEcologicalIndicators }); // reset so available is sum of years growth biomassAddedThisYear = 0; biomassConsumed = 0; } }
private void ONCLEMAgeResources(object sender, EventArgs e) { if (ZoneCLEM.IsEcologicalIndicatorsCalculationMonth()) { OnEcologicalIndicatorsCalculated(new EcolIndicatorsEventArgs() { Indicators = CurrentEcologicalIndicators }); // reset so available is sum of years growth biomassAddedThisYear = 0; biomassConsumed = 0; } }