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); }