public static void siteSuccession(Landis.Library.DensityCohorts.SiteCohorts siteCohorts) { int RDflag; float siteRD = SiteVars.SiteRD[siteCohorts.Site]; double GSO1 = EcoregionData.GSO1[siteCohorts.Ecoregion]; double GSO2 = EcoregionData.GSO2[siteCohorts.Ecoregion]; double GSO3 = EcoregionData.GSO3[siteCohorts.Ecoregion]; double GSO4 = EcoregionData.GSO4[siteCohorts.Ecoregion]; if (siteRD < GSO1) { RDflag = 0; } else if (siteRD >= GSO1 && siteRD < GSO2) { RDflag = 1; } else if (siteRD >= GSO2 && siteRD <= GSO3) { RDflag = 2; } else if (siteRD > GSO3 && siteRD <= GSO4) { RDflag = 3; } else { Debug.Assert(siteRD > GSO4); RDflag = 4; } if (0 == RDflag || 1 == RDflag || 2 == RDflag) { //GetSeedNumberOnSite(Row, Col); //SeedGermination(siteptr, l, RDflag); NaturalMortality(siteCohorts, 1);//kill the youngest of trees } else if (3 == RDflag) { NaturalMortality(siteCohorts, 0);//kill all ages of trees } else { NaturalMortality(siteCohorts, 0);//kill all ages of trees if (SiteVars.SiteRD[siteCohorts.Site] > GSO4) { SelfthinningTest(siteCohorts); SiteVars.TotalSiteRD(siteCohorts); } } }
//====NaturalMortality()==================================================================================================== public static void Selfthinning(Landis.Library.DensityCohorts.SiteCohorts siteCohorts) { double targetRD = SiteVars.SiteRD[siteCohorts.Site] - EcoregionData.GSO4[siteCohorts.Ecoregion]; double qmd = siteCohorts.siteQMD; float[] shadeArray = new float[] { 0.0f, 0.1f, 0.3f, 0.5f, 0.7f, 0.9f }; //SortedList<double, Landis.Library.DensityCohorts.ICohort> cohortMortality = new SortedList<double, Library.DensityCohorts.ICohort>(); SortedDictionary <int, double> cohortMortality = new SortedDictionary <int, double>(); for (int i = 0; i < siteCohorts.AllCohorts.Count; i++) { double reldia = siteCohorts.AllCohorts[i].Diameter / qmd; double mort = (0.84525 - (0.01074 * reldia) + (0.0000002 * Math.Pow(reldia, 3))) * (1 - shadeArray[siteCohorts.AllCohorts[i].Species.ShadeTolerance]); cohortMortality.Add(i, mort); } var sortedDict = from entry in cohortMortality orderby entry.Value descending select entry; var sortedMortality = sortedDict.ToDictionary(pair => pair.Key, pair => pair.Value); double countRD = targetRD; foreach (KeyValuePair <int, double> item in sortedMortality) { int deadTrees = (int)Math.Round(item.Value * siteCohorts.AllCohorts[item.Key].Treenumber); float deadRD = computeMortalityRD(siteCohorts.AllCohorts[item.Key], deadTrees); if (deadTrees > 0) { SiteVars.summaryLogMortality.Clear(); SummaryLogMortality slm = new SummaryLogMortality(); slm.Time = EcoregionData.ModelCore.CurrentTime; slm.SiteIndex = siteCohorts.Site.DataIndex; slm.EcoName = siteCohorts.Ecoregion.Name; slm.Species = siteCohorts.AllCohorts[item.Key].Species.Name; slm.Age = siteCohorts.AllCohorts[item.Key].Age; slm.TreeNumber = deadTrees; slm.Diameter = Math.Round(siteCohorts.AllCohorts[item.Key].Diameter, 1); slm.MortalityCause = "Competition"; SiteVars.summaryLogMortality.AddObject(slm); SiteVars.summaryLogMortality.WriteToFile(); } siteCohorts.AllCohorts[item.Key].ChangeTreenumber(-deadTrees); countRD -= deadRD; if (countRD < 0) { break; } } }
// Self thinning test public static void SelfthinningTest(Landis.Library.DensityCohorts.SiteCohorts siteCohorts) { double targetRD = SiteVars.SiteRD[siteCohorts.Site] - EcoregionData.GSO4[siteCohorts.Ecoregion]; double qmd = siteCohorts.siteQMD; float[] shadeArray = new float[] { 0.0f, 0.1f, 0.3f, 0.5f, 0.7f, 0.9f }; //SortedList<double, Landis.Library.DensityCohorts.ICohort> cohortMortality = new SortedList<double, Library.DensityCohorts.ICohort>(); SortedDictionary <int, double> cohortMortality = new SortedDictionary <int, double>(); for (int i = 0; i < siteCohorts.AllCohorts.Count; i++) { double reldia = siteCohorts.AllCohorts[i].Diameter / qmd; double mort = (0.84525 - (0.01074 * reldia) + (0.0000002 * Math.Pow(reldia, 3))) * (1 - shadeArray[siteCohorts.AllCohorts[i].Species.ShadeTolerance]); cohortMortality.Add(i, mort); } var sortedDict = from entry in cohortMortality orderby entry.Value descending select entry; var sortedMortality = sortedDict.ToDictionary(pair => pair.Key, pair => pair.Value); double countRD = targetRD; Random randomNumber = new Random(); while (countRD > 0) { foreach (KeyValuePair <int, double> item in sortedMortality) { if (siteCohorts.AllCohorts[item.Key].Treenumber <= 0 || countRD <= 0) { continue; } if (randomNumber.NextDouble() < item.Value) { int deadTrees = 1; float deadRD = computeMortalityRD(siteCohorts.AllCohorts[item.Key], deadTrees); siteCohorts.AllCohorts[item.Key].ChangeTreenumber(-deadTrees); countRD -= deadRD; } } } }
public static void TotalSiteRD(Landis.Library.DensityCohorts.SiteCohorts cohorts) { float siteRD = 0; Landis.Library.DensityCohorts.Cohort.SetSiteAccessFunctions(cohorts); if (cohorts == null) { SiteVars.SiteRD[cohorts.Site] = siteRD; } else { foreach (Landis.Library.DensityCohorts.ICohort cohort in cohorts.AllCohorts) { double tmp_term1 = Math.Pow((cohort.Diameter / 25.4), 1.605); float tmp_term2 = 10000 / SpeciesParameters.SpeciesDensity.AllSpecies[cohort.Species.Index].MaxSDI; int tmp_term3 = cohort.Treenumber; double tmp = tmp_term1 * tmp_term2 * tmp_term3 / Math.Pow(EcoregionData.ModelCore.CellLength, 2); siteRD += (float)tmp; } SiteVars.SiteRD[cohorts.Site] = siteRD; } //return siteRD; }
public static void NaturalMortality(Landis.Library.DensityCohorts.SiteCohorts siteCohorts, int StartAge) { double DQ_const = 3.1415926 / (4 * 0.0002471 * Math.Pow(EcoregionData.ModelCore.CellLength, 2) * Math.Pow(30.48, 2)); Random rand = new Random(); //kill all tree, else kill youngest tree if (StartAge == 0) { double tmpDQ = 0; foreach (Landis.Library.DensityCohorts.ICohort cohort in siteCohorts.AllCohorts) { if (SpeciesParameters.SpeciesDensity.AllSpecies[cohort.Species.Index].SpType >= 0) { tmpDQ += Math.Pow(cohort.Diameter, 2) * DQ_const * cohort.Treenumber; } } //==================================================================================================== foreach (Landis.Library.DensityCohorts.ICohort cohort in siteCohorts.AllCohorts) { if (SpeciesParameters.SpeciesDensity.AllSpecies[cohort.Species.Index].SpType >= 0) { double TmpMortality = Landis.Library.DensityCohorts.Cohorts.SuccessionTimeStep / 10 / (1.0 + Math.Exp(3.25309 - 0.00072647 * tmpDQ + 0.01668809 * cohort.Diameter / 2.54)); TmpMortality = (1.0f < TmpMortality ? 1.0f : TmpMortality); double DeadTree = cohort.Treenumber * TmpMortality; Debug.Assert(DeadTree <= UINT_MAX && DeadTree >= 0); int DeadTreeInt = (int)DeadTree; //if (DeadTree - DeadTreeInt >= 0.0001) if (DeadTree > DeadTreeInt) { if (rand.NextDouble() < 0.1) { DeadTreeInt++; } } if (DeadTreeInt >= cohort.Treenumber) { siteCohorts.RemoveCohort((Cohort)cohort, null); } else if (DeadTreeInt > 0) { cohort.ChangeTreenumber(-DeadTreeInt); } tmpDQ -= Math.Pow(cohort.Diameter, 2) * DQ_const * DeadTree; } else { cohort.ChangeTreenumber((int)Math.Pow(EcoregionData.ModelCore.CellLength, 2)); } } //==================================================================================================== } else //kill youngest tree { double tmpDQ = 0; foreach (Landis.Library.DensityCohorts.ICohort cohort in siteCohorts.AllCohorts) { if (SpeciesParameters.SpeciesDensity.AllSpecies[cohort.Species.Index].SpType >= 0) { tmpDQ += Math.Pow(cohort.Diameter, 2) * DQ_const * cohort.Treenumber; } } foreach (Landis.Library.DensityCohorts.ICohort cohort in siteCohorts.AllCohorts) { if (SpeciesParameters.SpeciesDensity.AllSpecies[cohort.Species.Index].SpType >= 0) { if (cohort.Age <= (Landis.Library.DensityCohorts.Cohorts.SuccessionTimeStep * StartAge)) { double TmpMortality = Landis.Library.DensityCohorts.Cohorts.SuccessionTimeStep / 10 / (1.0 + Math.Exp(3.25309 - 0.00072647 * tmpDQ + 0.01668809 * cohort.Diameter / 2.54)); TmpMortality = (1.0f < TmpMortality ? 1.0f : TmpMortality); double DeadTree = cohort.Treenumber * TmpMortality; Debug.Assert(DeadTree <= UINT_MAX && DeadTree >= 0); int DeadTreeInt = (int)DeadTree; //if (DeadTree - DeadTreeInt >= 0.0001) if (DeadTree > DeadTreeInt) { if (rand.NextDouble() < 0.1) { DeadTreeInt++; } } if (DeadTreeInt >= cohort.Treenumber) { siteCohorts.RemoveCohort((Cohort)cohort, null); } else if (DeadTreeInt > 0) { cohort.ChangeTreenumber(-DeadTreeInt); } tmpDQ -= Math.Pow(cohort.Diameter, 2) * DQ_const * DeadTree; } } else { cohort.ChangeTreenumber((int)Math.Pow(EcoregionData.ModelCore.CellLength, 2)); } } } }
//--------------------------------------------------------------------- public static void SetSiteAccessFunctions(SiteCohorts sitecohorts) { Cohort.ecoregion = sitecohorts.Ecoregion; Cohort.site = sitecohorts.Site; }