Exemplo n.º 1
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Raises a Cohort.DeathEvent.
        /// </summary>
        public static void Died(object     sender,
                                ICohort    cohort,
                                ActiveSite site,
                                PlugInType disturbanceType)
        {
            if (DeathEvent != null)
                DeathEvent(sender, new DeathEventArgs(cohort, site, disturbanceType));
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Gets the pair of percentages for a particular disturbance type.
 /// </summary>
 public PoolPercentages this[PlugInType disturbanceType]
 {
     get {
         PoolPercentages poolPercentages;
         if (percentages.TryGetValue(disturbanceType, out poolPercentages))
             return poolPercentages;
         return defaultPercentages;
     }
 }
Exemplo n.º 3
0
        //---------------------------------------------------------------------

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            PlugInType type = (PlugInType)obj;

            return(name == type.name);
        }
        public void AgeOnlyDisturbance()
        {
            Landis.Biomass.SiteCohorts.AgeOnlyDisturbanceEvent += AgeOnlyDisturbanceEvent;
            Landis.Biomass.Cohort.AgeOnlyDeathEvent += AgeOnlyCohortDeath;
            cohortsKilledByAgeOnlyDist.Clear();

            expectedDistType = RemoveAgeBetween5And30.DisturbanceType;
            expectedSite = activeSite2;
            CohortsRemoved(new RemoveAgeBetween5And30_AgeOnly(activeSite2));
            CheckDeadCohorts(cohortsKilledByAgeOnlyDist);

            Landis.Biomass.Cohort.AgeOnlyDeathEvent -= AgeOnlyCohortDeath;
            Landis.Biomass.SiteCohorts.AgeOnlyDisturbanceEvent -= AgeOnlyDisturbanceEvent;
        }
 public void BiomassDisturbance()
 {
     expectedDistType = RemoveAgeBetween5And30.DisturbanceType;
     expectedSite = activeSite;
     CohortsRemoved(new RemoveAgeBetween5And30_Biomass(activeSite));
 }
        public void SingleCohort_ZeroBiomass()
        {
            SiteCohorts cohorts = new SiteCohorts();
            const ushort initialBiomass = 100;
            cohorts.AddNewCohort(poputrem, initialBiomass);

            mockCalculator.CountCalled = 0;
            mockCalculator.Change = -2;

            expectedSender = cohorts[poputrem];
            expectedDistType = null;  // death during growth phase
            expectedSite = activeSite;
            deadCohorts.Clear();

            for (int time = 1; time <= 60; time++) {
                if (time % successionTimestep == 0)
                    Util.Grow(cohorts, successionTimestep, activeSite, true);
            }

            expectedCohorts.Clear();
            Util.CheckCohorts(expectedCohorts, cohorts);

            Assert.AreEqual(1, deadCohorts.Count);
            ICohort deadCohort = deadCohorts[0];
            Assert.AreEqual(poputrem, deadCohort.Species);
            Assert.AreEqual(initialBiomass / -mockCalculator.Change, deadCohort.Age);
            Assert.AreEqual(0, deadCohort.Biomass);
        }
        public void SingleCohort_LongevityReached()
        {
            SiteCohorts cohorts = new SiteCohorts();
            const ushort initialBiomass = 300;
            cohorts.AddNewCohort(poputrem, initialBiomass);

            mockCalculator.CountCalled = 0;
            mockCalculator.Change = 1;

            expectedSender = cohorts[poputrem];
            expectedDistType = null;  // death during growth phase
            expectedSite = activeSite;
            deadCohorts.Clear();

            //  Repeatedly grow for succession timesteps until longevity
            //  reached.
            int time = 0;
            do {
                 time += successionTimestep;
                Util.Grow(cohorts, successionTimestep, activeSite, true);
            } while (time <= poputrem.Longevity);

            expectedCohorts.Clear();
            Util.CheckCohorts(expectedCohorts, cohorts);

            //  Calculator called L times where L is longevity.  Inituitively,
            //  one would think since initial cohort's age is 1, it'd only take
            //  L-1 times to get to the max age (= L).  So the calculator
            //  should be called L-1 times.  But the combining of young cohorts
            //  at the first succession timestep (t_succ = 20) results in the
            //  calculator being called twice with cohort age = t_succ-1 (19).
            //  At the end of year 19, the cohort's age is 20 and the
            //  calculator has been called 19 times.  But at the start of year
            //  20, the combine-young-cohorts operation is done because it's a
            //  succession timestep.  The combine operation takes all the young
            //  cohorts (age <= t_succ = 20) and replaces them with one cohort
            //  with age = t_succ-1 (= 19).  This ensures that after the growth
            //  phase, the cohort's age will be t_succ (20).  So the growth
            //  phase of year 20 calls the calculator for the 20th time with
            //  cohort age 19.
            Assert.AreEqual(poputrem.Longevity, mockCalculator.CountCalled);

            Assert.AreEqual(1, deadCohorts.Count);
            ICohort deadCohort = deadCohorts[0];
            Assert.AreEqual(poputrem, deadCohort.Species);
            Assert.AreEqual(poputrem.Longevity, deadCohort.Age);
            Assert.AreEqual(initialBiomass + (poputrem.Longevity * mockCalculator.Change),
                            deadCohort.Biomass);
        }
        public void Init()
        {
            poputrem = Data.Species["poputrem"];

            bool[,] grid = new bool[,]{
                {true,  false},
                {false, true}
            };
            DataGrid<bool> dataGrid = new DataGrid<bool>(grid);
            ILandscape landscape = new Landscape.Landscape(dataGrid);
            activeSite = landscape[1,1];
            activeSite2 = landscape[2,2];

            expectedSender = null;
            expectedDistType = null;
            expectedSite = null;

            mockCalculator = new MockCalculator();
            Landis.Biomass.Cohorts.Initialize(successionTimestep,
                                              mockCalculator);

            Landis.Biomass.Cohort.DeathEvent += CohortDeath;

            expectedCohorts = new Dictionary<ISpecies, ushort[]>();
            deadCohorts = new List<ICohort>();
            cohortsKilledByAgeOnlyDist = new List<ICohort>();
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Raises a Cohort.AgeOnlyDeathEvent.
 /// </summary>
 public static void KilledByAgeOnlyDisturbance(object     sender,
     ICohort    cohort,
     ActiveSite site,
     PlugInType disturbanceType)
 {
     if (AgeOnlyDeathEvent != null)
         AgeOnlyDeathEvent(sender, new DeathEventArgs(cohort, site, disturbanceType));
 }
        //---------------------------------------------------------------------
        /// <summary>
        /// Gets the pair of percentages for a particular disturbance type.
        /// </summary>
        public PoolPercentages this[PlugInType disturbanceType]
        {
            get {
                PoolPercentages poolPercentages;
                //UI.WriteLine("   Trying to acquire pool percentages for {0}.", disturbanceType);
                if (percentages.TryGetValue(disturbanceType, out poolPercentages))
                    return poolPercentages;

                return defaultPercentages;
            }
            set {
                //PoolPercentages poolPercentages;
                percentages[disturbanceType] = value;
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        public DisturbanceEventArgs(ActiveSite site,
                                    PlugInType disturbanceType)
        {
            this.site = site;
            this.disturbanceType = disturbanceType;
        }