本文整理汇总了C#中ISiteCohorts类的典型用法代码示例。如果您正苦于以下问题:C# ISiteCohorts类的具体用法?C# ISiteCohorts怎么用?C# ISiteCohorts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISiteCohorts类属于命名空间,在下文中一共展示了ISiteCohorts类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeAge
//---------------------------------------------------------------------
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: InitialBiomass
//---------------------------------------------------------------------
/// <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;
}
示例3: CheckCohorts
/// <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);
}
示例4: InitialBiomass
//---------------------------------------------------------------------
/// <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;
}
示例5: ComputeBiomass
//---------------------------------------------------------------------
public static int ComputeBiomass(ISiteCohorts cohorts)
{
int total = 0;
if (cohorts != null)
foreach (ISpeciesCohorts speciesCohorts in cohorts)
total += ComputeBiomass(speciesCohorts);
return total;
}
示例6: ComputeTotalBiomass
//---------------------------------------------------------------------
private static int ComputeTotalBiomass(ISiteCohorts cohorts)
{
int total = 0;
if (cohorts != null)
foreach (ISpeciesCohorts speciesCohorts in cohorts)
{
total += ComputeSpeciesBiomass(speciesCohorts);
}
return total;
}
示例7: ComputeLivingBiomass
//---------------------------------------------------------------------
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: CalculateNLimits
//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: ComputeNonYoungBiomass
//---------------------------------------------------------------------
/// <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: InitialBiomass
//---------------------------------------------------------------------
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: GetMaxAge
//---------------------------------------------------------------------
/// <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: InitialBiomass
//---------------------------------------------------------------------
/// <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: ComputeBiomass
//---------------------------------------------------------------------
/// <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: ComputeResorbedN
//---------------------------------------------------------------------
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;
}
示例15: GetAgeRichness
//---------------------------------------------------------------------
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;
}