//--------------------------------------------------------------------- /// <summary> /// Grows an individual cohort for a year, incrementing its age by 1 /// and updating its biomass for annual growth and mortality. /// </summary> /// <param name="index"> /// The index of the cohort to grow; it must be between 0 and Count - 1. /// </param> /// <param name="site"> /// The site where the species' cohorts are located. /// </param> /// <returns> /// The index of the next younger cohort. Note this may be the same /// as the index passed in if that cohort dies due to senescence. /// </returns> public int GrowCohort(int index, ActiveSite site, bool annualTimestep) { Debug.Assert(0 <= index && index <= cohortData.Count); Debug.Assert(site != null); Cohort cohort = new Cohort(species, cohortData[index]); Debug.Assert(cohort.WoodBiomass <= cohort.WoodBiomass + cohort.LeafBiomass); Debug.Assert(cohort.LeafBiomass <= cohort.WoodBiomass + cohort.LeafBiomass); //if (isDebugEnabled) // log.DebugFormat(" grow cohort: {0}, {1} yrs, {2} Mg/ha", // cohort.Species.Name, cohort.Age, cohort.Biomass); // Check for senescence if (cohort.Age >= species.Longevity) { RemoveCohort(index, cohort, site, null); return(index); } if (annualTimestep) { cohort.IncrementAge(); } float[] biomassChange = Cohorts.BiomassCalculator.ComputeChange(cohort, site); Debug.Assert(-(cohort.WoodBiomass + cohort.LeafBiomass) <= biomassChange[0] + biomassChange[1]); // Cohort can't loss more biomass than it has //UI.WriteLine("B={0:0.00}, Age={1}, delta={2}", cohort.Biomass, cohort.Age, biomassChange); cohort.ChangeWoodBiomass(biomassChange[0]); cohort.ChangeLeafBiomass(biomassChange[1]); //if (isDebugEnabled) // log.DebugFormat(" biomass: change = {0}, cohort = {1}, site = {2}", // biomassChange, cohort.Biomass, siteBiomass); if (cohort.WoodBiomass + cohort.LeafBiomass > 0) { cohortData[index] = cohort.Data; return(index + 1); } else { RemoveCohort(index, cohort, site, null); return(index); } }
//--------------------------------------------------------------------- /// <summary> /// Computes how much a disturbance damages the cohorts by reducing /// their biomass. /// </summary> /// <returns> /// The total of all the cohorts' biomass reductions. /// </returns> public int DamageBySpecies(IDisturbance disturbance) { // Go backwards through list of cohort data, so the removal of an // item doesn't mess up the loop. isMaturePresent = false; int totalReduction = 0; for (int i = cohortData.Count - 1; i >= 0; i--) { Cohort cohort = new Cohort(species, cohortData[i]); float[] reduction = disturbance.ReduceOrKillMarkedCohort(cohort); //int reduction = disturbance.ReduceOrKillMarkedCohort(cohort); totalReduction += (int)(reduction[0] + reduction[1]); float fRed = (totalReduction / (float)cohort.Biomass); if (totalReduction > 0) { if (totalReduction < cohort.Biomass) { //Console.WriteLine(" DamageBySpecies Partial mortality: {0}, {1} yrs, {2} Mg/ha", cohort.Species.Name, cohort.Age, cohort.Biomass); ReduceCohort(i, cohort, disturbance.CurrentSite, disturbance.Type, fRed); //RMS 12/2016 if (reduction[1] < cohort.LeafBiomass) { cohort.ChangeLeafBiomass(-reduction[1]); cohortData[i] = cohort.Data; } if (reduction[0] < cohort.WoodBiomass) { cohort.ChangeWoodBiomass(-reduction[0]); cohortData[i] = cohort.Data; } } else { // Assume that if all wood biomass lost, the cohort is dead //Console.WriteLine(" DamageBySpecies Total mortality: {0}, {1} yrs, {2} Mg/ha", cohort.Species.Name, cohort.Age, cohort.Biomass); RemoveCohort(i, cohort, disturbance.CurrentSite, disturbance.Type); cohort = null; } } if (cohort != null) { if (cohort.Age >= species.Maturity) { isMaturePresent = true; } } } return(totalReduction); }
//--------------------------------------------------------------------- public int MarkCohorts(Landis.Library.BiomassCohorts.IDisturbance disturbance) { // Go backwards through list of cohort data, so the removal of an // item doesn't mess up the loop. isMaturePresent = false; int totalReduction = 0; for (int i = cohortData.Count - 1; i >= 0; i--) { Cohort cohort = new Cohort(species, cohortData[i]); int reduction = disturbance.ReduceOrKillMarkedCohort(cohort); if (reduction > 0) { totalReduction += reduction; if (reduction < cohort.Biomass) { float fRed = (float)reduction / (float)cohort.Biomass; //Console.WriteLine(" MarkCohorts Partial mortality: {0}, {1} yrs, {2} Mg/ha", cohort.Species.Name, cohort.Age, cohort.Biomass); ReduceCohort(i, cohort, disturbance.CurrentSite, disturbance.Type, fRed); //RMS 12/2016 float deltaWood = (-1) * fRed * (float)cohort.Data.WoodBiomass; cohort.ChangeWoodBiomass(deltaWood); float deltaLeaf = (-1) * fRed * (float)cohort.Data.LeafBiomass; cohort.ChangeLeafBiomass(deltaLeaf); if (cohortData[i].Age >= species.Maturity) { isMaturePresent = true; } } else { //Console.WriteLine(" MarkCohorts Total mortality: {0}, {1} yrs, {2} Mg/ha", cohort.Species.Name, cohort.Age, cohort.Biomass); RemoveCohort(i, cohort, disturbance.CurrentSite, disturbance.Type); cohort = null; } } else { if (cohortData[i].Age >= species.Maturity) { isMaturePresent = true; } } } return(totalReduction); }
//--------------------------------------------------------------------- public int MarkCohorts(Landis.Library.BiomassCohorts.IDisturbance disturbance) { isSpeciesCohortDamaged.SetAllFalse(Count); // Go backwards through list of cohort data, so the removal of an // item doesn't mess up the loop. isMaturePresent = false; int totalReduction = 0; for (int i = cohortData.Count - 1; i >= 0; i--) { if (isSpeciesCohortDamaged[i]) { Cohort cohort = new Cohort(species, cohortData[i]); int reduction = disturbance.ReduceOrKillMarkedCohort(cohort); if (reduction > 0) { totalReduction += reduction; if (reduction < cohort.Biomass) { float fRed = reduction / cohort.Biomass; float deltaWood = (-1) * fRed * (float)cohort.Data.WoodBiomass; cohort.ChangeWoodBiomass(deltaWood); float deltaLeaf = (-1) * fRed * (float)cohort.Data.LeafBiomass; cohort.ChangeLeafBiomass(deltaLeaf); } else { Cohort.KilledByAgeOnlyDisturbance(disturbance, cohort, disturbance.CurrentSite, disturbance.Type); RemoveCohort(i, cohort, disturbance.CurrentSite, disturbance.Type); cohort = null; } } } else if (cohortData[i].Age >= species.Maturity) { isMaturePresent = true; } } return(totalReduction); }
//--------------------------------------------------------------------- /// <summary> /// Grows an individual cohort for a year, incrementing its age by 1 /// and updating its biomass for annual growth and mortality. /// </summary> /// <param name="index"> /// The index of the cohort to grow; it must be between 0 and Count - 1. /// </param> /// <param name="site"> /// The site where the species' cohorts are located. /// </param> /// <returns> /// The index of the next younger cohort. Note this may be the same /// as the index passed in if that cohort dies due to senescence. /// </returns> public int GrowCohort(int index, ActiveSite site, bool annualTimestep) { Debug.Assert(0 <= index && index <= cohortData.Count); Debug.Assert(site != null); Cohort cohort = new Cohort(species, cohortData[index]); Debug.Assert(cohort.WoodBiomass <= cohort.WoodBiomass + cohort.LeafBiomass); Debug.Assert(cohort.LeafBiomass <= cohort.WoodBiomass + cohort.LeafBiomass); // Check for senescence if (cohort.Age >= species.Longevity) { RemoveCohort(index, cohort, site, null); return(index); } if (annualTimestep) { cohort.IncrementAge(); } float[] biomassChange = Cohorts.BiomassCalculator.ComputeChange(cohort, site); Debug.Assert(-(cohort.WoodBiomass + cohort.LeafBiomass) <= biomassChange[0] + biomassChange[1]); // Cohort can't loss more biomass than it has cohort.ChangeWoodBiomass(biomassChange[0]); cohort.ChangeLeafBiomass(biomassChange[1]); if (cohort.WoodBiomass + cohort.LeafBiomass > 0) { cohortData[index] = cohort.Data; return(index + 1); } else { RemoveCohort(index, cohort, site, null); return(index); } }
//--------------------------------------------------------------------- /// <summary> /// Computes how much a disturbance damages the cohorts by reducing /// their biomass. /// </summary> /// <returns> /// The total of all the cohorts' biomass reductions. /// </returns> public int DamageBySpecies(IDisturbance disturbance) { // Go backwards through list of cohort data, so the removal of an // item doesn't mess up the loop. isMaturePresent = false; int totalReduction = 0; for (int i = cohortData.Count - 1; i >= 0; i--) { Cohort cohort = new Cohort(species, cohortData[i]); float[] reduction = disturbance.ReduceOrKillMarkedCohort(cohort); if (reduction[0] + reduction[1] > 0) { totalReduction += (int)(reduction[0] + reduction[1]); if (reduction[1] < cohort.LeafBiomass) { cohort.ChangeLeafBiomass(-reduction[1]); cohortData[i] = cohort.Data; } if (reduction[0] < cohort.WoodBiomass) { cohort.ChangeWoodBiomass(-reduction[0]); cohortData[i] = cohort.Data; } else // Assume that if all wood biomass lost, the cohort is dead { RemoveCohort(i, cohort, disturbance.CurrentSite, disturbance.Type); cohort = null; } } if (cohort != null && cohort.Age >= species.Maturity) { isMaturePresent = true; } } return(totalReduction); }