public void OrganonStandGrowthApi() { TestStand.WriteTreeHeader(this.TestContext !); foreach (OrganonVariant variant in TestConstant.Variants) { OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant); // check crown competition API TestStand stand = OrganonTest.CreateDefaultStand(configuration); float crownCompetitionFactor = OrganonStandDensity.GetCrownCompetitionByHeight(variant, stand)[0]; Assert.IsTrue(crownCompetitionFactor >= 0.0F); Assert.IsTrue(crownCompetitionFactor <= TestConstant.Maximum.CrownCompetitionFactor); OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth | ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant); // recalculate heights and crown ratios for all trees Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration(); foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values) { OrganonGrowth.SetIngrowthHeightAndCrownRatio(variant, stand, treesOfSpecies, treesOfSpecies.Count, calibrationBySpecies); } OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth | ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant); // run Organon growth simulation stand = OrganonTest.CreateDefaultStand(configuration); if (configuration.IsEvenAge) { // stand error if less than one year to grow to breast height stand.AgeInYears = stand.BreastHeightAgeInYears + 2; } stand.SetQuantiles(); stand.WriteTreesAsCsv(this.TestContext !, variant, 0, false); TestStand initialStand = new TestStand(stand); TreeLifeAndDeath treeGrowth = new TreeLifeAndDeath(); for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep) { OrganonGrowth.Grow(simulationStep, configuration, stand, calibrationBySpecies); treeGrowth.AccumulateGrowthAndMortality(stand); OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowth | ExpectedTreeChanges.HeightGrowth, OrganonWarnings.LessThan50TreeRecords, stand, variant); stand.WriteTreesAsCsv(this.TestContext !, variant, variant.GetEndYear(simulationStep), false); } OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowth | ExpectedTreeChanges.HeightGrowth, treeGrowth, initialStand, stand); OrganonTest.Verify(calibrationBySpecies); } }
protected static void GrowPspStand(PspStand huffmanPeak, TestStand stand, OrganonVariant variant, int startYear, int endYear, string baseFileName) { OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant); TestStand initialTreeData = new TestStand(stand); TreeLifeAndDeath treeGrowth = new TreeLifeAndDeath(); Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration(); if (configuration.IsEvenAge) { // stand error if less than one year to grow to breast height stand.AgeInYears = stand.BreastHeightAgeInYears + 2; } TestStandDensity density = new TestStandDensity(stand, variant); using StreamWriter densityWriter = density.WriteToCsv(baseFileName + " density.csv", variant, startYear); TreeQuantiles quantiles = new TreeQuantiles(stand); using StreamWriter quantileWriter = quantiles.WriteToCsv(baseFileName + " quantiles.csv", variant, startYear); using StreamWriter treeGrowthWriter = stand.WriteTreesToCsv(baseFileName + " tree growth.csv", variant, startYear); for (int simulationStep = 0, year = startYear + variant.TimeStepInYears; year <= endYear; year += variant.TimeStepInYears, ++simulationStep) { OrganonGrowth.Grow(simulationStep, configuration, stand, calibrationBySpecies); treeGrowth.AccumulateGrowthAndMortality(stand); huffmanPeak.AddIngrowth(year, stand, density); OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowthOrNoChange | ExpectedTreeChanges.HeightGrowthOrNoChange, stand, variant); density = new TestStandDensity(stand, variant); density.WriteToCsv(densityWriter, variant, year); quantiles = new TreeQuantiles(stand); quantiles.WriteToCsv(quantileWriter, variant, year); stand.WriteTreesToCsv(treeGrowthWriter, variant, year); } OrganonTest.Verify(ExpectedTreeChanges.ExpansionFactorConservedOrIncreased | ExpectedTreeChanges.DiameterGrowthOrNoChange | ExpectedTreeChanges.HeightGrowthOrNoChange, treeGrowth, initialTreeData, stand); OrganonTest.Verify(calibrationBySpecies); }
protected static void Verify(ExpectedTreeChanges expectedGrowth, TreeLifeAndDeath treeGrowth, TestStand initialStand, TestStand finalStand) { foreach (Trees finalTreesOfSpecies in finalStand.TreesBySpecies.Values) { float[] diameterGrowthOfSpecies = treeGrowth.TotalDbhGrowthInInches[finalTreesOfSpecies.Species]; float[] deathOfSpecies = treeGrowth.TotalDeadExpansionFactor[finalTreesOfSpecies.Species]; float[] heightGrowthOfSpecies = treeGrowth.TotalHeightGrowthInFeet[finalTreesOfSpecies.Species]; Trees initialTreesOfSpecies = initialStand.TreesBySpecies[finalTreesOfSpecies.Species]; for (int treeIndex = 0; treeIndex < finalTreesOfSpecies.Count; ++treeIndex) { float totalDbhGrowth = diameterGrowthOfSpecies[treeIndex]; if (expectedGrowth.HasFlag(ExpectedTreeChanges.DiameterGrowth)) { Assert.IsTrue(totalDbhGrowth > 0.0F); Assert.IsTrue(totalDbhGrowth <= TestConstant.Maximum.DiameterInInches); } else if (expectedGrowth.HasFlag(ExpectedTreeChanges.DiameterGrowthOrNoChange)) { Assert.IsTrue(totalDbhGrowth >= 0.0F); Assert.IsTrue(totalDbhGrowth <= TestConstant.Maximum.DiameterInInches); } else { Assert.IsTrue(totalDbhGrowth == 0.0F); } float totalHeightGrowth = heightGrowthOfSpecies[treeIndex]; if (expectedGrowth.HasFlag(ExpectedTreeChanges.HeightGrowth)) { Assert.IsTrue(totalHeightGrowth > 0.0F); Assert.IsTrue(totalHeightGrowth <= TestConstant.Maximum.HeightInFeet); } else if (expectedGrowth.HasFlag(ExpectedTreeChanges.HeightGrowthOrNoChange)) { Assert.IsTrue(totalHeightGrowth >= 0.0F); Assert.IsTrue(totalHeightGrowth <= TestConstant.Maximum.HeightInFeet); } else { Assert.IsTrue(totalHeightGrowth == 0.0F); } float totalDeadExpansionFactor = deathOfSpecies[treeIndex]; Assert.IsTrue(totalDeadExpansionFactor >= 0.0F); Assert.IsTrue(totalDeadExpansionFactor <= TestConstant.Maximum.ExpansionFactor); float initialTotalExpansionFactor = initialTreesOfSpecies.LiveExpansionFactor[treeIndex] + initialTreesOfSpecies.DeadExpansionFactor[treeIndex]; float finalTotalExpansionFactor = finalTreesOfSpecies.LiveExpansionFactor[treeIndex] + totalDeadExpansionFactor; float expansionFactorRatio = finalTotalExpansionFactor / initialTotalExpansionFactor; Assert.IsTrue(expansionFactorRatio >= 0.999F); if (expectedGrowth.HasFlag(ExpectedTreeChanges.ExpansionFactorConservedOrIncreased)) { Assert.IsTrue(initialTotalExpansionFactor >= 0.0F); } else { Assert.IsTrue(initialTotalExpansionFactor > 0.0F); Assert.IsTrue(finalTotalExpansionFactor > 0.0F); Assert.IsTrue(expansionFactorRatio <= 1.001F); } Assert.IsTrue(finalTotalExpansionFactor <= TestConstant.Maximum.ExpansionFactor); } for (int treeIndex = finalTreesOfSpecies.Count; treeIndex < finalTreesOfSpecies.Capacity; ++treeIndex) { Assert.IsTrue(diameterGrowthOfSpecies[treeIndex] == 0.0F); Assert.IsTrue(deathOfSpecies[treeIndex] == 0.0F); Assert.IsTrue(heightGrowthOfSpecies[treeIndex] == 0.0F); Assert.IsTrue(initialTreesOfSpecies.DbhGrowth[treeIndex] == 0.0F); Assert.IsTrue(initialTreesOfSpecies.HeightGrowth[treeIndex] == 0.0F); Assert.IsTrue(finalTreesOfSpecies.DbhGrowth[treeIndex] == 0.0F); Assert.IsTrue(finalTreesOfSpecies.HeightGrowth[treeIndex] == 0.0F); } } }