コード例 #1
0
        //---------------------------------------------------------------------
        public static int ComputeAge(ISiteCohorts cohorts)
        {
            int dominantAge = 0;
            Dictionary<int, int> ageDictionary = new Dictionary<int, int>();
            if (cohorts != null)
                foreach (ISpeciesCohorts speciesCohorts in cohorts)
                {
                    foreach (ICohort cohort in speciesCohorts)
                    {
                        int age = cohort.Age;
                        int biomass = cohort.Biomass;
                        if (ageDictionary.ContainsKey(age))
                        {
                            ageDictionary[age] = ageDictionary[age] + biomass;
                        }
                        else
                        {
                            ageDictionary[age] = biomass;
                        }
                    }
                }

            int maxBiomass = 0;
            foreach (var kvp in ageDictionary)
            {
                if (kvp.Value > maxBiomass)
                {
                    dominantAge = kvp.Key;
                    maxBiomass = kvp.Value;
                }

            }

            return dominantAge;
        }
コード例 #2
0
        /// <summary>
        /// Checks that two sets of site cohorts are the same.  Also checks the
        /// site's total biomass.
        /// </summary>
        /// <param name="expected">
        /// Keys are expected species.  A species' value is an array of the
        /// ages and biomasses of its expected cohorts from oldest to youngest.
        /// Ages and biomasses are alternate:
        /// 
        /// <pre>
        ///     item 0 = expected age of oldest cohort
        ///     item 1 =    "     biomass  "      "
        ///     item 2 =    "     age of 2nd oldest cohort
        ///     item 3 =    "     biomass "    "      "
        ///     ...
        /// </pre>
        /// </param>
        /// <param name="actual">
        /// The actual site cohorts to verify.
        /// </param>
        public static void CheckCohorts(Dictionary<ISpecies, ushort[]> expected,
                                        ISiteCohorts                   actual)
        {
            int expectedTotalBiomass = 0;

            foreach (ISpecies species in expected.Keys) {
                ISpeciesCohorts speciesCohorts = actual[species];
                Assert.IsNotNull(speciesCohorts);

                //  Assume cohorts are ordered from oldest to youngest
                ushort[] expectedCohortData = expected[species];
                Assert.AreEqual(expectedCohortData.Length, speciesCohorts.Count * 2);
                int i = 0;
                foreach (ICohort cohort in speciesCohorts) {
                    Assert.AreEqual(expectedCohortData[i], cohort.Age);
                    Assert.AreEqual(expectedCohortData[i+1], cohort.Biomass);
                    expectedTotalBiomass += expectedCohortData[i+1];
                    i += 2;
                }
            }

            //  Check if any extra species beyond those that were expected
            foreach (ISpeciesCohorts speciesCohorts in actual)
                Assert.IsTrue(expected.ContainsKey(speciesCohorts.Species));

            Assert.AreEqual(expectedTotalBiomass, actual.TotalBiomass);
        }
コード例 #3
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Computes the initial biomass for a cohort at a site.
        /// </summary>
        public static float[] InitialBiomass(ISpecies species, ISiteCohorts siteCohorts,
            ActiveSite  site)
        {
            IEcoregion ecoregion = PlugIn.ModelCore.Ecoregion[site];

            double leafFrac = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACleaf;

            double B_ACT = SiteVars.ActualSiteBiomass(site);
            double B_MAX = SpeciesData.B_MAX_Spp[species][ecoregion];

            //  Initial biomass exponentially declines in response to
            //  competition.
            double initialBiomass = 0.002 * B_MAX * Math.Exp(-1.6 * B_ACT / B_MAX);

            initialBiomass = Math.Max(initialBiomass, 5.0);

            double initialLeafB = initialBiomass * leafFrac;
            double initialWoodB = initialBiomass - initialLeafB;
            double[] initialB = new double[2]{initialWoodB, initialLeafB};
            float[] initialWoodLeafBiomass = new float[2] { (float)initialB[0], (float)initialB[1] };

            //PlugIn.ModelCore.UI.WriteLine("Yr={0},Mo={1}, InitialB={2:0.0}, InitBleaf={3:0.00}, InitBwood={4:0.00}. LeafFrac={5:0.0}", PlugIn.ModelCore.CurrentTime, month, initialBiomass, initialB[1], initialB[0], leafFrac);
            //PlugIn.ModelCore.UI.WriteLine("Yr={0},Mo={1}, B_MAX={2:0.0}, B_ACT={3:0.00}", PlugIn.ModelCore.CurrentTime, month, B_MAX, B_ACT);

            return initialWoodLeafBiomass;
        }
コード例 #4
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Computes the initial biomass for a cohort at a site.
        /// </summary>
        public static float[] InitialBiomass(ISpecies species, ISiteCohorts siteCohorts,
            ActiveSite  site)
        {
            IEcoregion ecoregion = PlugIn.ModelCore.Ecoregion[site];

            double leafFrac = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACleaf;
            double branchFraction = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACbranch;
            //double Ndemand = 0.0;

            double B_ACT = SiteVars.ActualSiteBiomass(site);
            double B_MAX = SpeciesData.B_MAX_Spp[species][ecoregion];

            //  Initial biomass exponentially declines in response to
            //  competition.
            double initialBiomass = 0.002 * B_MAX *
                                    Math.Exp(-1.6 * B_ACT / B_MAX);

            //Initial biomass is limited by nitrogen availability.
            //initialBiomass *= SpeciesData.NLimits[species];
            initialBiomass = Math.Max(initialBiomass, 5.0);

            double initialLeafB = initialBiomass * leafFrac;
            double initialBranchB = initialBiomass* branchFraction;
            double initialWoodB = initialBiomass*(1 - leafFrac - branchFraction);
            double[] initialB = new double[3] { initialWoodB, initialBranchB, initialLeafB };

            //PlugIn.ModelCore.Log.WriteLine("Yr={0},Mo={1}, InitialB={2:0.0}, InitBleaf={3:0.00}, InitBwood={4:0.00}. LeafFrac={5:0.0}", PlugIn.ModelCore.CurrentTime, month, initialBiomass, initialB[1], initialB[0], leafFrac);
            //PlugIn.ModelCore.Log.WriteLine("Yr={0},Mo={1}, B_MAX={2:0.0}, B_ACT={3:0.00}", PlugIn.ModelCore.CurrentTime, month, B_MAX, B_ACT);

               float[] initialWoodLeafBiomass = new float[3] { (float)initialB[0], (float)initialB[1], (float)initialB[2] }; //wang?

            return initialWoodLeafBiomass;
        }
コード例 #5
0
        //---------------------------------------------------------------------

        public static int ComputeBiomass(ISiteCohorts cohorts)
        {
            int total = 0;
            if (cohorts != null)
                foreach (ISpeciesCohorts speciesCohorts in cohorts)
                    total += ComputeBiomass(speciesCohorts);
            return total;
        }
コード例 #6
0
 //---------------------------------------------------------------------
 private static int ComputeTotalBiomass(ISiteCohorts cohorts)
 {
     int total = 0;
     if (cohorts != null)
         foreach (ISpeciesCohorts speciesCohorts in cohorts)
         {
             total += ComputeSpeciesBiomass(speciesCohorts);
         }
     return total;
 }
コード例 #7
0
 //---------------------------------------------------------------------
 public static int ComputeLivingBiomass(ISiteCohorts cohorts)
 {
     int total = 0;
     if (cohorts != null)
         foreach (ISpeciesCohorts speciesCohorts in cohorts)
             foreach (ICohort cohort in speciesCohorts)
                 total += (int) (cohort.WoodBiomass + cohort.LeafBiomass);
             //total += ComputeBiomass(speciesCohorts);
     return total;
 }
コード例 #8
0
        //New method for calculating N limits, called from Century.cs Run method before calling Grow
        //Iterates through cohorts, assigning each a N gathering efficiency based on fine root biomass
        //and N tolerance.
        public static double CalculateNLimits(ActiveSite site, ISiteCohorts siteCohorts)
        {
            // BEN:   Your new method belongs here
            //Iterate through the first time, assigning each cohort un un-normalized N multiplier
            double NMultTotal=0.0;
            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
                foreach (ICohort cohort in speciesCohorts)
                {
                            int Ntolerance = SpeciesData.NTolerance[cohort.Species];

                            //NMultiplier is a measure of how much N a cohort can gather relative to other cohorts
                            double NMultiplier = CalculateNMultiplier(cohort.Biomass,Ntolerance);
                            NMultTotal += NMultiplier;
                            Dictionary<int,double> newEntry = new Dictionary<int,double>();
                            newEntry.Add(cohort.Age,NMultiplier);

                            if (CohortNlimits.ContainsKey(cohort.Species.Index))
                            {
                               CohortNlimits[cohort.Species.Index].Add(cohort.Age,NMultiplier);
                            }
                            else
                            {
                               CohortNlimits.Add(cohort.Species.Index,newEntry);
                            }

                }

            double availableN = SiteVars.MineralN[site];  // g/m2

            //Console.WriteLine("NMultTotal="+NMultTotal);

            //Iterate through a second time now that we have total N multiplier
            //Divide through by total and multiply by total available N so each cohort has a max N value
            //and the sum of cohort max N values is the site available N
            double totalNUptake = 0.0;
            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
                        foreach (ICohort cohort in speciesCohorts)
                        {
                           double NMultiplier=CohortNlimits[cohort.Species.Index][cohort.Age];
                           double Nfrac=NMultiplier/NMultTotal;
                           CohortNlimits[cohort.Species.Index][cohort.Age] = Nfrac * availableN;

                           totalNUptake += Nfrac * availableN;
                           //Console.WriteLine("species={0} age={1} NMult={2:0.00} Nfrac={3:0.0000}",cohort.Species.Name,cohort.Age,NMultiplier,Nfrac);
                        }

            //Console.WriteLine("Total max N uptake = {0:0.0000}, availableN = {1:0.0000}, availableN-uptake={2:0.0000}", totalNUptake,availableN,availableN-totalNUptake);
            if (availableN - totalNUptake < -0.001 * availableN)
            {
                    UI.WriteLine("   ERROR:  Total max N uptake = {0:0.000}, availableN = {1:0.000}.", totalNUptake, availableN);
                    throw new ApplicationException("Error: Max N uptake > availableN.  See AvailableN.cs");
            }

            return 0.0;
        }
コード例 #9
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Computes the total biomass for all the cohorts, not including young cohorts.
 /// </summary>
 public static int ComputeNonYoungBiomass(ISiteCohorts siteCohorts)
 {
     int totalBiomass = 0;
     foreach (ISpeciesCohorts speciesCohorts in siteCohorts) {
         foreach (ICohort cohort in speciesCohorts) {
             if (cohort.Age >= successionTimeStep)
                 totalBiomass += cohort.Biomass;
         }
     }
     return totalBiomass;
 }
コード例 #10
0
        //---------------------------------------------------------------------
        private InitialBiomass(ISiteCohorts cohorts,
            
            Layer surfaceDeadWood,
            Layer surfaceDeadBranch,
            
            Layer surfaceStructural,
            Layer surfaceMetabolic,
            
            Layer soilDeadWood,
            Layer soilStructural,
            Layer soilMetabolic,
            
            Layer som1surface,
            Layer som1soil,
            Layer som2,
            Layer som3,
            
            double mineralN,
            double cohortLeafC,
            double cohortLeafN,
            double cohortWoodC,
            double cohortWoodN,
            
            double cohortBranchC,
            double cohortBranchN
            
            )
        {
            this.cohorts = cohorts;

            this.surfaceDeadWood = surfaceDeadWood;
            this.surfaceDeadBranch = surfaceDeadBranch;

            this.surfaceStructural = surfaceStructural;
            this.surfaceMetabolic = surfaceMetabolic;

            this.soilDeadWood = soilDeadWood;
            this.soilStructural = soilStructural;
            this.soilMetabolic = soilMetabolic;

            this.som1surface = som1surface;
            this.som1soil = som1soil;
            this.som2 = som2;
            this.som3 = som3;

            this.mineralN = mineralN;
            this.cohortLeafC = cohortLeafC;
            this.cohortLeafN = cohortLeafN;
            this.cohortWoodC = cohortWoodC;
            this.cohortWoodN = cohortWoodN;

            this.cohortBranchC = cohortBranchC;
            this.cohortBranchN = cohortBranchN;
        }
コード例 #11
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Gets the maximum age among all cohorts at a site.
        /// </summary>
        /// <returns>
        /// The age of the oldest cohort or 0 if there are no cohorts.
        /// </returns>
        public static ushort GetMaxAge(ISiteCohorts cohorts)
        {
            if (cohorts == null)
                return 0;
            ushort max = 0;
            foreach (ISpeciesCohorts speciesCohorts in cohorts) {
                ushort maxSpeciesAge = GetMaxAge(speciesCohorts);
                if (maxSpeciesAge > max)
                    max = maxSpeciesAge;
            }
            return max;
        }
コード例 #12
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Computes the initial biomass for a cohort at a site.
        /// </summary>
        public static float[] InitialBiomass(ISpecies species, ISiteCohorts siteCohorts,
                                            ActiveSite  site)
        {
            IEcoregion ecoregion = PlugIn.ModelCore.Ecoregion[site];

            double leafFrac = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACleaf;
            //double Ndemand = 0.0;

            double B_ACT = SiteVars.ActualSiteBiomass(site);
            double B_MAX = SpeciesData.B_MAX_Spp[species][ecoregion];

            //  Initial biomass exponentially declines in response to
            //  competition.
            double initialBiomass = 0.002 * B_MAX *
                                    Math.Exp(-1.6 * B_ACT / B_MAX);

            //Initial biomass is limited by nitrogen availability.
            //initialBiomass *= SpeciesData.NLimits[species];
            initialBiomass = Math.Max(initialBiomass, 5.0);

            double initialLeafB = initialBiomass * leafFrac;
            double initialWoodB = initialBiomass - initialLeafB;
            double[] initialB = new double[2]{initialWoodB, initialLeafB};

            //PlugIn.ModelCore.Log.WriteLine("Yr={0},Mo={1}, InitialB={2:0.0}, InitBleaf={3:0.00}, InitBwood={4:0.00}. LeafFrac={5:0.0}", PlugIn.ModelCore.CurrentTime, month, initialBiomass, initialB[1], initialB[0], leafFrac);
            //PlugIn.ModelCore.Log.WriteLine("Yr={0},Mo={1}, B_MAX={2:0.0}, B_ACT={3:0.00}", PlugIn.ModelCore.CurrentTime, month, B_MAX, B_ACT);

            // Note:  The following if statement is critical for ensuring that young cohorts
            // get established properly.
            /*if (SiteVars.MineralN[site] <= 0 || initialBiomass < 5.0)
            {
                initialBiomass = Math.Min(initialBiomass, 5.0);
                initialB[0] = initialBiomass * (1.0 - leafFrac);
                initialB[1] = initialBiomass * leafFrac;
            }*/

            //Ndemand = AvailableN.CalculateCohortNDemand(species, site, initialB);
            //SiteVars.MineralN[site] -= Math.Min(SiteVars.MineralN[site], Nreduction);

            /*if (SiteVars.MineralN[site] > Nreduction)
                SiteVars.MineralN[site] -= Nreduction;
            else
            {
                double NreductionAdjusted = SiteVars.MineralN[site];
                SiteVars.MineralN[site] = 0.0;
                initialB[0] = NreductionAdjusted / Nreduction;
                initialB[1] = NreductionAdjusted / Nreduction;
            }*/

            float[] initialWoodLeafBiomass = new float[2]{(float) initialB[0], (float) initialB[1]};

            return initialWoodLeafBiomass;
        }
コード例 #13
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Computes the total biomass for all the cohorts at a site, and the
 /// total biomass for all the young cohorts.
 /// </summary>
 public static int ComputeBiomass(ISiteCohorts siteCohorts,
     out int      youngBiomass)
 {
     youngBiomass = 0;
     int totalBiomass = 0;
     foreach (ISpeciesCohorts speciesCohorts in siteCohorts) {
         foreach (ICohort cohort in speciesCohorts) {
             totalBiomass += cohort.Biomass;
             if (cohort.Age < successionTimeStep)
                 youngBiomass += cohort.Biomass;
         }
     }
     return totalBiomass;
 }
コード例 #14
0
 //---------------------------------------------------------------------
 public static ushort GetAgeRichness(ISiteCohorts siteCohorts)
 {
     //return total count of cohorts
     ushort count = 0;
     if (siteCohorts == null)
         return 0;
     foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
     {
         foreach (ICohort cohort in speciesCohorts)
         {
             count++;
         }
     }
     return count;
 }
コード例 #15
0
        //---------------------------------------------------------------------
        public static void ComputeResorbedN(ISiteCohorts cohorts, ActiveSite site, int month)
        {
            if (cohorts != null)
                foreach (ISpeciesCohorts speciesCohorts in cohorts)
                    foreach (ICohort cohort in speciesCohorts)
                    {
                        // Resorbed N:  We are assuming that any leaves dropped as a function of normal
                        // growth and maintenance (e.g., fall senescence) will involve resorption of leaf N.
                        double resorbedN = AvailableN.CalculateResorbedN(site, cohort.Species, cohort.LeafBiomass, month);

                        AvailableN.SetResorbedNallocation(cohort, resorbedN);

                    }
            return;
        }
コード例 #16
0
 private InitialBiomass(ISiteCohorts cohorts,
                        Pool deadWoodyPool,
                        Pool deadNonWoodyPool,
                        float water,
                        float annualtrans,
                        float canopylai,
                        float canopylaimax,
                        float subcanopypar 
                        )
 {
     this.canopylaimax = canopylaimax;
     this.cohorts = cohorts;
     this.deadWoodyPool = deadWoodyPool;
     this.deadNonWoodyPool = deadNonWoodyPool;
     this.water = water;
     this.annualtrans = annualtrans;
     this.canopylai = canopylai;
     this.subcanopypar = subcanopypar;
 }
コード例 #17
0
        //---------------------------------------------------------------------
        //Use E = Hprime / ln S   where S apparently is # species)
        //where Hprime = -sum (pI * ln(pI))   where pI is proportion of individuals found in Ith species
        //from Magurran, A.  1988.  Ecological diversity and its measurements.  Princeton, NJ: Princeton University Press.  Pp 35-37)
        //Return E * 100 to fit within ushort range
        public static ushort GetAgeEvenness(ISiteCohorts siteCohorts)
        {
            double E = 0;
            double Hprime = 0;
            double proportion=0;
            ushort evenness = 0;
            ushort total_count = 0;
            Dictionary<ushort, ushort> cohort_counts = new Dictionary<ushort, ushort>();
            if (siteCohorts == null)
                return 0;
            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
            {
                foreach (ICohort cohort in speciesCohorts)
                {
                    total_count++;
                    if (!cohort_counts.ContainsKey(cohort.Age))
                    {
                        cohort_counts.Add(cohort.Age, 1);
                    }
                    else
                    {
                        cohort_counts[cohort.Age]++;
                    }
                }
            }

            foreach (KeyValuePair<ushort,ushort> cohortIter in cohort_counts)
            {
                proportion = (double)cohortIter.Value / (double)total_count;
                Hprime += proportion * System.Math.Log(proportion);
            }
            Hprime = - Hprime;
            E = Hprime / System.Math.Log(cohort_counts.Count);
            evenness = (ushort)(E * 100.0);

            return evenness;
        }
コード例 #18
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Computes the initial biomass for a cohort at a site.
        /// </summary>
        public static float[] InitialBiomass(ISpecies species, ISiteCohorts siteCohorts,
            ActiveSite  site)
        {
            IEcoregion ecoregion = PlugIn.ModelCore.Ecoregion[site];

            double leafFrac = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACleaf;

            double B_ACT = SiteVars.ActualSiteBiomass(site);
            double B_MAX = SpeciesData.B_MAX_Spp[species][ecoregion];

            //  Initial biomass exponentially declines in response to
            //  competition.
            double initialBiomass = 0.002 * B_MAX * Math.Exp(-1.6 * B_ACT / B_MAX);

            initialBiomass = Math.Max(initialBiomass, 5.0);

            double initialLeafB = initialBiomass * leafFrac;
            double initialWoodB = initialBiomass - initialLeafB;
            double[] initialB = new double[2]{initialWoodB, initialLeafB};

            float[] initialWoodLeafBiomass = new float[2]{(float) initialB[0], (float) initialB[1]};

            return initialWoodLeafBiomass;
        }
コード例 #19
0
 //---------------------------------------------------------------------
 //Note: don't call Var directly, it will be too big!
 public static uint GetVarAge(ISiteCohorts siteCohorts)
 {
     if (siteCohorts == null)
         return 0;
     ushort avg = GetAvgAge(siteCohorts);
     double sum = 0;
     ushort count = 0;
     foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
     {
         foreach (ICohort cohort in speciesCohorts)
         {
             sum += System.Math.Pow(cohort.Age - avg, 2);
             count++;
         }
     }
     if (count <= 1)
         return 0;
     return (uint)System.Math.Round((sum / (count - 1)));
 }
コード例 #20
0
 //---------------------------------------------------------------------
 public static ushort GetStdDevAge(ISiteCohorts siteCohorts)
 {
     if (siteCohorts == null)
         return 0;
     ushort std_dev = (ushort)System.Math.Sqrt(GetVarAge(siteCohorts));
     return std_dev;
 }
コード例 #21
0
 //---------------------------------------------------------------------
 public static ushort GetMinAge(ISiteCohorts siteCohorts)
 {
     if (siteCohorts == null)
         return 0;
     ushort min = 65535;//maxof ushort
     foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
     {
         ushort minSpeciesAge = GetMinAge(speciesCohorts);
         if (minSpeciesAge < min)
             min = minSpeciesAge;
     }
     return min;
 }
コード例 #22
0
        //---------------------------------------------------------------------
        public static ushort GetMedianAge(ISiteCohorts siteCohorts)
        {
            if (siteCohorts == null)
                return 0;
            ushort median = 0;
            double dbl_median = 0.0;

            List<ushort> cohort_ages = new List<ushort>();
            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
            {
                foreach(ICohort cohort in speciesCohorts)
                {
                    cohort_ages.Add(cohort.Age);
                }
            }
            int count = cohort_ages.Count;
            if (count == 0)
            {
                return 0;
            }

            else if (count == 1)
            {
                return cohort_ages[0];
            }

            cohort_ages.Sort();//sorts in ascending order

            if (count % 2 == 0)
            {
                dbl_median = (cohort_ages[count / 2] + cohort_ages[(count / 2) - 1]) / 2.0;
                median = (ushort)dbl_median;
            }
            else
            {
                median = cohort_ages[count / 2];
            }
            return median;
        }
コード例 #23
0
 //---------------------------------------------------------------------
 public static ISiteCohorts Clone(ActiveSite site, ISiteCohorts site_cohorts)
 {
     ISiteCohorts clone = new SiteCohorts();
      foreach (ISpeciesCohorts speciesCohorts in site_cohorts)
          foreach (Cohort cohort in speciesCohorts)
          {
              clone.AddNewCohort(cohort);
          }
      return clone;
 }
コード例 #24
0
        //---------------------------------------------------------------------
        private static void ComputeTotalCohortCN(ActiveSite site, ISiteCohorts cohorts)
        {
            SiteVars.CohortLeafC[site] = 0;
            SiteVars.CohortFRootC[site] = 0;
            SiteVars.CohortLeafN[site] = 0;
            SiteVars.CohortFRootN[site] = 0;
            SiteVars.CohortWoodC[site] = 0;
            SiteVars.CohortCRootC[site] = 0;
            SiteVars.CohortWoodN[site] = 0;
            SiteVars.CohortCRootN[site] = 0;

            if (cohorts != null)
                foreach (ISpeciesCohorts speciesCohorts in cohorts)
                    foreach (ICohort cohort in speciesCohorts)
                        CalculateCohortCN(site, cohort);
            return;
        }
コード例 #25
0
        /// <summary>
        /// Grows all cohorts at a site for a specified number of years.
        /// Litter is decomposed following the Century model.
        /// </summary>
        public static ISiteCohorts Run(ActiveSite site,
                                       int years,
                                       bool isSuccessionTimeStep)
        {
            ISiteCohorts siteCohorts = SiteVars.Cohorts[site];
            IEcoregion   ecoregion   = PlugIn.ModelCore.Ecoregion[site];

            for (int y = 0; y < years; ++y)
            {
                Year = y + 1;

                if (Climate.Future_MonthlyData.ContainsKey(PlugIn.FutureClimateBaseYear + y + PlugIn.ModelCore.CurrentTime - years))
                {
                    ClimateRegionData.AnnualWeather[ecoregion] = Climate.Future_MonthlyData[PlugIn.FutureClimateBaseYear + y - years + PlugIn.ModelCore.CurrentTime][ecoregion.Index];
                }

                //PlugIn.ModelCore.UI.WriteLine("PlugIn_FutureClimateBaseYear={0}, y={1}, ModelCore_CurrentTime={2}, CenturyTimeStep = {3}, SimulatedYear = {4}.", PlugIn.FutureClimateBaseYear, y, PlugIn.ModelCore.CurrentTime, years, (PlugIn.FutureClimateBaseYear + y - years + PlugIn.ModelCore.CurrentTime));

                SiteVars.ResetAnnualValues(site);

                // Next, Grow and Decompose each month
                int[] months = new int[12] {
                    6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5
                };

                if (OtherData.CalibrateMode)
                {
                    //months = new int[12]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; This output will not match normal mode due to differences in initialization
                    months = new int[12] {
                        6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5
                    }
                }
                ;

                PlugIn.AnnualWaterBalance = 0;

                for (MonthCnt = 0; MonthCnt < 12; MonthCnt++)
                {
                    // Calculate mineral N fractions based on coarse root biomass.  Only need to do once per year.
                    if (MonthCnt == 0)
                    {
                        AvailableN.CalculateMineralNfraction(site);
                    }
                    //PlugIn.ModelCore.UI.WriteLine("SiteVars.MineralN = {0:0.00}, month = {1}.", SiteVars.MineralN[site], i);

                    Month = months[MonthCnt];

                    SiteVars.MonthlyAGNPPcarbon[site][Month]      = 0.0;
                    SiteVars.MonthlyBGNPPcarbon[site][Month]      = 0.0;
                    SiteVars.MonthlyNEE[site][Month]              = 0.0;
                    SiteVars.MonthlyResp[site][Month]             = 0.0;
                    SiteVars.MonthlyStreamN[site][Month]          = 0.0;
                    SiteVars.MonthlyLAI[site][Month]              = 0.0;
                    SiteVars.MonthlySoilWaterContent[site][Month] = 0.0;
                    SiteVars.SourceSink[site].Carbon              = 0.0;
                    SiteVars.TotalWoodBiomass[site] = Main.ComputeWoodBiomass((ActiveSite)site);

                    double ppt = ClimateRegionData.AnnualWeather[ecoregion].MonthlyPrecip[Main.Month];

                    double monthlyNdeposition;
                    if (PlugIn.Parameters.AtmosNintercept != -1 && PlugIn.Parameters.AtmosNslope != -1)
                    {
                        monthlyNdeposition = PlugIn.Parameters.AtmosNintercept + (PlugIn.Parameters.AtmosNslope * ppt);
                    }
                    else
                    {
                        monthlyNdeposition = ClimateRegionData.AnnualWeather[ecoregion].MonthlyNDeposition[Main.Month];
                    }

                    if (monthlyNdeposition < 0)
                    {
                        throw new System.ApplicationException("Error: Nitrogen deposition less than zero.");
                    }

                    ClimateRegionData.MonthlyNDeposition[ecoregion][Month] = monthlyNdeposition;
                    ClimateRegionData.AnnualNDeposition[ecoregion]        += monthlyNdeposition;
                    SiteVars.MineralN[site] += monthlyNdeposition;
                    //PlugIn.ModelCore.UI.WriteLine("Ndeposition={0},MineralN={1:0.00}.", monthlyNdeposition, SiteVars.MineralN[site]);

                    double liveBiomass = (double)ComputeLivingBiomass(siteCohorts);
                    double baseFlow, stormFlow, AET;

                    if (OtherData.SoilWaterVersion64)
                    {
                        SoilWater.RunVersion64(y, Month, liveBiomass, site, out baseFlow, out stormFlow, out AET);
                    }
                    else
                    {
                        SoilWater.Run(y, Month, liveBiomass, site, out baseFlow, out stormFlow, out AET);
                    }

                    PlugIn.AnnualWaterBalance += ppt - AET;

                    // Calculate N allocation for each cohort
                    AvailableN.SetMineralNallocation(site);

                    if (MonthCnt == 11)
                    {
                        siteCohorts.Grow(site, (y == years && isSuccessionTimeStep), true);
                    }
                    else
                    {
                        siteCohorts.Grow(site, (y == years && isSuccessionTimeStep), false);
                    }

                    WoodLayer.Decompose(site);
                    LitterLayer.Decompose(site);
                    SoilLayer.Decompose(site);

                    // Volatilization loss as a function of the mineral N which remains after uptake by plants.
                    // ML added a correction factor for wetlands since their denitrification rate is double that of wetlands
                    // based on a review paper by Seitziner 2006.

                    double volatilize = (SiteVars.MineralN[site] * PlugIn.Parameters.DenitrificationRate);

                    //PlugIn.ModelCore.UI.WriteLine("BeforeVol.  MineralN={0:0.00}.", SiteVars.MineralN[site]);

                    SiteVars.MineralN[site]            -= volatilize;
                    SiteVars.SourceSink[site].Nitrogen += volatilize;
                    SiteVars.Nvol[site] += volatilize;

                    //if (OtherData.Henne_WaterMode)
                    //    SoilWaterHenne.Leach(site, baseFlow, stormFlow);
                    //else
                    SoilWater.Leach(site, baseFlow, stormFlow);

                    SiteVars.MonthlyNEE[site][Month] -= SiteVars.MonthlyAGNPPcarbon[site][Month];
                    SiteVars.MonthlyNEE[site][Month] -= SiteVars.MonthlyBGNPPcarbon[site][Month];
                    SiteVars.MonthlyNEE[site][Month] += SiteVars.SourceSink[site].Carbon;
                    SiteVars.FineFuels[site]          = (SiteVars.SurfaceStructural[site].Carbon + SiteVars.SurfaceMetabolic[site].Carbon) * 2.0;
                    //SiteVars.FineFuels[site] = (System.Math.Min(1.0, (double) (PlugIn.ModelCore.CurrentTime - SiteVars.HarvestTime[site]) * 0.1));
                }
            }

            ComputeTotalCohortCN(site, siteCohorts);

            return(siteCohorts);
        }
コード例 #26
0
        //---------------------------------------------------------------------
        //New method for calculating competition limits.
        //Iterates through cohorts, assigning each a competitive efficiency
        public static void CalculateCompetition(ISiteCohorts siteCohorts)
        {
            //Iterate through the first time, assigning each cohort an un-normalized C multiplier
            CohortCompetition = new Dictionary<int, Dictionary<int, double>>();

            double CMultTotal = 0.0;
            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
                foreach (ICohort cohort in speciesCohorts)
                {
                    double CMultiplier = Math.Max(Math.Sqrt(cohort.Biomass), 1.0);

                    CMultTotal += CMultiplier;
                    Dictionary<int,double> newEntry = new Dictionary<int,double>();
                    newEntry.Add(cohort.Age, CMultiplier);

                    if (CohortCompetition.ContainsKey(cohort.Species.Index))
                    {
                       CohortCompetition[cohort.Species.Index].Add(cohort.Age,CMultiplier);
                    }
                    else
                    {
                       CohortCompetition.Add(cohort.Species.Index, newEntry);
                    }

                }

            //Iterate through a second time now that we have total C multiplier
            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
                foreach (ICohort cohort in speciesCohorts)
                {
                    double CMultiplier = CohortCompetition[cohort.Species.Index][cohort.Age];
                    double Cfraction = CMultiplier / CMultTotal;

                    CohortCompetition[cohort.Species.Index][cohort.Age] = Cfraction;
                }
        }
コード例 #27
0
        //---------------------------------------------------------------------
        public static ushort GetAvgAge(ISiteCohorts siteCohorts)
        {
            if (siteCohorts == null)
                return 0;
            ushort avg = 0;
            uint sum = 0;
            ushort count = 0;

            foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
            {
                foreach (ICohort cohort in speciesCohorts)
                {
                    sum += cohort.Age;
                    count++;
                }
            }

            if (count == 0)
            {
                return 0;
            }

            avg = (ushort)(sum / count);
            return avg;
        }
コード例 #28
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Computes the total biomass for all the cohorts at a site.
        /// </summary>
        public static int ComputeBiomass(ISiteCohorts siteCohorts)
        {
            int youngBiomass;

            return(ComputeBiomass(siteCohorts, out youngBiomass));
        }
コード例 #29
0
		//---------------------------------------------------------------------

		public Community(ushort                          mapCode,
		                 ISiteCohorts<AgeCohort.ICohort> cohorts)
		{
			this.mapCode = mapCode;
			this.cohorts = cohorts;
		}
コード例 #30
0
 //---------------------------------------------------------------------
 public static ISiteCohorts Clone(ISiteCohorts site_cohorts)
 {
     ISiteCohorts clone = new SiteCohorts();
     foreach (ISpeciesCohorts speciesCohorts in site_cohorts)
         foreach (ICohort cohort in speciesCohorts)
             clone.AddNewCohort(cohort.Species, cohort.Age, cohort.WoodBiomass, cohort.LeafBiomass);  //species.cohorts.Add(speciesCohorts.Clone());
     return clone;
 }
コード例 #31
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Computes the total biomass for all the cohorts at a site.
        /// </summary>
        public static int ComputeBiomass(ISiteCohorts<ICohort> siteCohorts)
        {
            int youngBiomass;
            return ComputeBiomass(siteCohorts, out youngBiomass);
        }
コード例 #32
0
        //---------------------------------------------------------------------

        private InitialBiomass(ISiteCohorts cohorts)
        {
            this.cohorts = cohorts;
        }
コード例 #33
0
        //---------------------------------------------------------------------
        private byte CalcForestType(ISiteCohorts<AgeCohort.ICohort> cohorts,
            IForestType[]                   forestTypes)
        {
            double[] forTypValue = new double[forestTypes.Length];
            int forTypeCnt = 0;
            foreach(IForestType ftype in forestTypes)
            {
                ushort maxSpeciesAge = 0;
                IDataset SpeciesDataset = Model.Species;
                foreach(ISpecies species in SpeciesDataset)
                {
                    double sppValue = 0.0;
                    ISpeciesCohorts<AgeCohort.ICohort> speciesCohorts =
                        cohorts[species];
                    maxSpeciesAge = MaxAge(speciesCohorts);

                    if(maxSpeciesAge > 0)
                        sppValue = (double) maxSpeciesAge /
                        (double) species.Longevity *
                        (double) reclassCoefs[species.Index];

                    if(ftype[species.Index] != 0)
                    {
                        if(ftype[species.Index] == -1)
                            forTypValue[forTypeCnt] -= sppValue;
                        if(ftype[species.Index] == 1)
                            forTypValue[forTypeCnt] += sppValue;
                    }
                }
                forTypeCnt++;
            }

            int finalForestType = 0;
            double maxValue = 0.0;
            forTypeCnt = 0;
            foreach(IForestType ftype in forestTypes)
            {
                //System.Console.WriteLine("ForestTypeNum={0}, Value={1}.",forTypeCnt,forTypValue[forTypeCnt]);
                if(forTypValue[forTypeCnt]>maxValue)
                {
                    maxValue = forTypValue[forTypeCnt];
                    finalForestType = forTypeCnt+1;
                }
                forTypeCnt++;
            }
            return (byte) finalForestType;
        }