/// <summary>
        /// Passed anonymously to succession modules to compute defoliation
        /// In succession modules defoliation is computed per-cohort, hence cohortBiomass parameter
        /// </summary>
        /// <param name="active"></param>
        /// <param name="species"></param>
        /// <param name="cohortBiomass"></param>
        /// <param name="siteBiomass"></param>
        /// <returns></returns>
        //public static double InsectDefoliate(ActiveSite active, ISpecies species, int cohortBiomass, int siteBiomass)
        public static double InsectDefoliate(ICohort cohort, ActiveSite active, int siteBiomass)
        {
            double totalDefoliation = 0.0;

            InsectDefoliation id = null;

            foreach (IChange lcc in SiteVars.LandUse[active].LandCoverChanges)
            {
                if (lcc.GetType() == typeof(InsectDefoliation))
                {
                    id = (lcc as InsectDefoliation);
                    if (id.repeat)
                    {
                        CohortDefoliation.Compute = InsectDefoliate;
                    }
                    else if (Model.Core.CurrentTime > id.harvestTime)
                    {
                        //Model.Core.UI.WriteLine("Disabling defoliation after harvest time: " + Model.Core.CurrentTime);
                        CohortDefoliation.Compute = DontCompute;
                        id = null;
                        break;
                    }
                    break;
                }
            }

            if (id != null)
            {
                //Landis.Extension.Succession.BiomassPnET.Cohort defolCohort = (cohort as Landis.Extension.Succession.BiomassPnET.Cohort);
                ICohort defolCohort = cohort;
                if (id.landCoverSelectors.ContainsKey(defolCohort.Species.Name))
                {
                    Percentage percentage = null;
                    id.landCoverSelectors[defolCohort.Species.Name].Selects(defolCohort, out percentage);

                    if (percentage == null)
                    {
                        //Model.Core.UI.WriteLine("Null percent");
                    }
                    else
                    {
                        totalDefoliation = percentage.Value;
                    }

                    if (totalDefoliation > 1.0)  // Cannot exceed 100% defoliation
                    {
                        totalDefoliation = 1.0;
                    }
                }
            }

            return(totalDefoliation);
        }
Exemple #2
0
        LandCover.IChange ProcessLandCoverChange(InputVar <string> landCoverChangeType)
        {
            InputVar <bool> repeatableHarvest = new InputVar <bool>("RepeatHarvest?");
            bool            repeatHarvest     = false;

            if (ReadOptionalVar(repeatableHarvest))
            {
                repeatHarvest = repeatableHarvest.Value.Actual;
            }
            LandCover.IChange landCoverChange = null;
            if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName)
            {
                landCoverChange = noLandCoverChange;
            }
            else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName)
            {
                LandCover.LandCover.DontParseTrees = true;
                PartialThinning.CohortSelectors.Clear();    //Clear static storage selector to prevent writing across land uses
                InputValues.Register <AgeRange>(PartialThinning.ReadAgeOrRange);
                ICohortSelector selector = selector = ReadSpeciesAndCohorts("LandUse",
                                                                            ParameterNames.Plant,
                                                                            "Tony Bonanza",
                                                                            "LandCoverChange");
                ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector,
                                                                              Main.ExtType);
                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();

                landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant, repeatHarvest);
                PartialThinning.CohortSelectors.Clear();    //Prevent interactions with Biomass Harvest
                LandCover.LandCover.DontParseTrees = false;
            }
            else if (landCoverChangeType.Value.Actual == LandCover.InsectDefoliation.TypeName)
            {
                //Insects will reduce biomass of cohorts rather than directly affecting demographics
                InputValues.Register <AgeRange>(LandCover.LandCover.ReadAgeOrRange);
                ICohortSelector selector = ReadSpeciesAndCohorts("LandUse",
                                                                 ParameterNames.Plant,
                                                                 "Vito Tortellini",
                                                                 "LandCoverChange");
                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();
                landCoverChange = new LandCover.InsectDefoliation(LandCover.LandCover.CohortSelectors, speciesToPlant, repeatHarvest);
                LandCover.LandCover.CohortSelectors.Clear();    //Clear static storage selector to prevent writing across land uses
            }
            else
            {
                throw new InputValueException(landCoverChangeType.Value.String,
                                              "\"{0}\" is not a type of land cover change",
                                              landCoverChangeType.Value.Actual);
            }
            //landCoverChange.PrintLandCoverDetails();
            return(landCoverChange);
        }