//--------------------------------------------------------------------- /// <summary> /// Removes the cohorts which are damaged by a disturbance. /// </summary> public void DamageBy(ICohortDisturbance disturbance) { // Go backwards through list of ages, so the removal of an age // doesn't mess up the loop. isMaturePresent = false; for (int i = ages.Count - 1; i >= 0; i--) { ICohort cohort = new Cohort(species, ages[i]); if (disturbance.Damage(cohort)) { ages.RemoveAt(i); Cohort.Died(this, cohort, disturbance.CurrentSite, disturbance.Type); } else if (ages[i] >= species.Maturity) { isMaturePresent = true; } } }
//--------------------------------------------------------------------- /// <summary> /// Grows all the cohorts by advancing their ages. /// </summary> /// <param name="years"> /// The number of years to advance each cohort's age. /// </param> /// <param name="successionTimestep"> /// Indicates whether the current timestep is a succession timestep. /// If so, then all young cohorts (i.e., those whose ages are less than /// or equal to the succession timestep are combined into a single /// cohort whose age is the succession timestep. /// </param> /// <param name="site"> /// The site where the cohorts are located. /// </param> public void Grow(ushort years, ActiveSite site, int?successionTimestep) { // Update ages for (int i = 0; i < ages.Count; i++) { if (successionTimestep.HasValue && (ages[i] < successionTimestep.Value)) { // Young cohort ages[i] = (ushort)successionTimestep.Value; } else { ages[i] += years; } } // Combine young cohorts if succession timestep if (successionTimestep.HasValue) { // Go backwards through list of ages, so the removal of an age // doesn't mess up the loop. bool left1YoungCohort = false; for (int i = ages.Count - 1; i >= 0; i--) { if (ages[i] == successionTimestep.Value) { // Young cohort if (left1YoungCohort) { ages.RemoveAt(i); } else { left1YoungCohort = true; } } } } // Now go through ages and check for age-related mortality and // senescence. Again go backwards through the list, so the // removal of an age doesn't mess up the loop. isMaturePresent = false; for (int i = ages.Count - 1; i >= 0; i--) { bool cohortDies = false; ushort age = ages[i]; if (age > species.Longevity) { cohortDies = true; } else if (age >= 0.8 * species.Longevity) { // Below is the annual age-related mortality probability, // so we need to check it for each year of growth. double ageRelatedMortalityProb = (4 * ((double)age / species.Longevity) - 3) / 10; for (int j = years; j > 0; j--) { if (Landis.Util.Random.GenerateUniform() < ageRelatedMortalityProb) { cohortDies = true; break; } } } if (cohortDies) { ages.RemoveAt(i); Cohort.Died(this, new Cohort(species, age), site, null); } else if (age >= species.Maturity) { isMaturePresent = true; } } }