Esempio n. 1
0
        public static void GrowCohorts(ActiveSite site,
                                       DateTime Time,
                                       DateTime ToTime,
                                       bool issuccessionTimestep)
        {
            if (PlugIn.Cohorts[site] == null)
            {
                return;
            }

            while (Time.CompareTo(ToTime) < 0)
            {
                if (Time.Month == 1)
                {
                    if (issuccessionTimestep && tstep > 1)//&& ClimateDependentData.Data[PlugIn.Date[site]] != null
                    {
                        PlugIn.Cohorts[site].CombineCohorts(site, tstep, Time.Year);
                    }

                    CanopyBiomass.SubCanopyPARmax[site] = float.MinValue;
                    Hydrology.AnnualTranspiration[site] = 0;

                    //CanopyBiomass.DefineAgeLayers(site);
                    CanopyBiomass.DefineBiomassLayers(site);

                    CanopyBiomass.CanopyLAI[site] = 0;
                    PlugIn.Cohorts[site].IncrementCohortsAge();
                }

                Hydrology.UpdateSiteHydrology(Time, site);

                CanopyBiomass.SimulateCanopy(Time, site);

                if (issuccessionTimestep)
                {
                    EstablishmentProbability.Compute(Time, site);
                }

                ForestFloor.Decomposition(site);

                SiteOutput.UpdateSiteData(Time, site);
                CanopyBiomass.GrossPsn[site] = 0;
                CanopyBiomass.NetPsn[site]   = 0;
                CanopyBiomass.AutotrophicRespiration[site] = 0;
                ForestFloor.HeterotrophicRespiration[site] = 0;
                Hydrology.Transpiration[site] = 0;

                Time = Time.AddMonths(1);
            }
            CanopyBiomass.RemoveDeadCohorts(site);

            PlugIn.Cohorts[site].UpdateMaturePresent();

            SiteOutput.WriteSiteData(site);

            DisturbanceDefoliation.Defoliate(site);
        }
Esempio n. 2
0
        public SiteConditions(ActiveSite site, ICommunity initialCommunity)
        {
            cohorts = new SiteCohorts();

            canopy = new Canopy();
            if (PlugIn.HasSiteOutput[site] == true)
            {
                siteoutput = new SiteOutput(site);
                estoutput  = new EstablishmentOutput(site);
            }

            this.site = site;


            foreach (ISpecies spc in PlugIn.modelCore.Species)
            {
                deadcohortages[spc] = new List <int>();
            }

            uint key = ComputeKey(initialCommunity.MapCode, PlugIn.ModelCore.Ecoregion[site].MapCode);

            SiteConditions s = GetFromKey(key);

            if (s != null)
            {
                return;
            }

            //  If we don't have a sorted list of age cohorts for the initial
            //  community, make the list

            List <Landis.Library.AgeOnlyCohorts.ICohort> sortedAgeCohorts;

            if (!sortedCohorts.TryGetValue(initialCommunity.MapCode, out sortedAgeCohorts))
            {
                sortedAgeCohorts = PlugIn.RankCohortAgesOldToYoung(initialCommunity.Cohorts);
                sortedCohorts[initialCommunity.MapCode] = sortedAgeCohorts;
            }
            hydrology     = new Hydrology(PlugIn.modelCore.Ecoregion[site]);
            forestfloor   = new ForestFloor();
            cohorts       = new SiteCohorts();
            establishment = new EstablishmentProbability(site);


            if (sortedAgeCohorts.Count == 0)
            {
                return;
            }

            //PlugIn.ModelCore.UI.WriteLine("Making Biomass Cohorts "+ site);
            BiomassSpinUp(sortedAgeCohorts, site);

            initialSites[key] = this;
            return;
        }
Esempio n. 3
0
        public SiteConditions GetFromKey(uint key)
        {
            SiteConditions s = null;

            if (initialSites.TryGetValue(key, out s) && siteoutput == null)
            {
                hydrology     = s.hydrology;
                establishment = s.Establishment;

                cohorts = new SiteCohorts();
                foreach (ISpeciesCohorts speciesCohorts in s.cohorts)
                {
                    foreach (Cohort cohort in speciesCohorts)
                    {
                        Cohort newcohort = new Cohort(cohort);
                        cohorts.AddNewCohort(newcohort, PlugIn.TStep);
                    }
                }
                forestfloor  = s.forestfloor;
                canopylaimax = s.CanopyLAImax;
            }
            return(s);
        }
        public SiteConditions(ActiveSite site, ICommunity initialCommunity)
        {
            cohorts = new SiteCohorts();

            canopy = new Canopy();
            if (PlugIn.HasSiteOutput[site] == true)
            {
                siteoutput = new SiteOutput(site);
                estoutput = new EstablishmentOutput(site);
            }

            this.site = site;

            foreach (ISpecies spc in PlugIn.modelCore.Species)
            {
                deadcohortages[spc] = new List<int>();
            }

            uint key = ComputeKey(initialCommunity.MapCode, PlugIn.ModelCore.Ecoregion[site].MapCode);

            SiteConditions s = GetFromKey(key);

            if (s != null) return;

            //  If we don't have a sorted list of age cohorts for the initial
            //  community, make the list

            List<Landis.Library.AgeOnlyCohorts.ICohort> sortedAgeCohorts;
            if (!sortedCohorts.TryGetValue(initialCommunity.MapCode, out sortedAgeCohorts))
            {
                sortedAgeCohorts = PlugIn.RankCohortAgesOldToYoung(initialCommunity.Cohorts);
                sortedCohorts[initialCommunity.MapCode] = sortedAgeCohorts;
            }
            hydrology = new Hydrology(PlugIn.modelCore.Ecoregion[site]);
            forestfloor = new ForestFloor();
            cohorts = new SiteCohorts();
            establishment = new EstablishmentProbability(site);

            if (sortedAgeCohorts.Count == 0) return;

            //PlugIn.ModelCore.UI.WriteLine("Making Biomass Cohorts "+ site);
            BiomassSpinUp(sortedAgeCohorts, site);

            initialSites[key] = this;
            return;
        }
        public SiteConditions GetFromKey(uint key)
        {
            SiteConditions s=null;
            if (initialSites.TryGetValue(key, out s) && siteoutput == null)
            {
                hydrology = s.hydrology;
                establishment = s.Establishment;

                cohorts = new SiteCohorts();
                foreach (ISpeciesCohorts speciesCohorts in s.cohorts)
                {
                    foreach (Cohort cohort in speciesCohorts)
                    {
                        Cohort newcohort = new Cohort(cohort);
                        cohorts.AddNewCohort(newcohort, PlugIn.TStep);
                    }
                }
                forestfloor = s.forestfloor;
                canopylaimax = s.CanopyLAImax;
            }
            return s;
        }
        public override void Initialize()
        {
            PlugIn.ModelCore.UI.WriteLine("Initializing " + Names.ExtensionName + " version " + typeof(PlugIn).Assembly.GetName().Version);
            Cohort.DeathEvent += DeathEvent;

            Litter         = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.Biomass.Pool>();
            WoodyDebris    = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.Biomass.Pool>();
            sitecohorts    = PlugIn.ModelCore.Landscape.NewSiteVar <SiteCohorts>();
            FineFuels      = ModelCore.Landscape.NewSiteVar <Double>();
            PressureHead   = ModelCore.Landscape.NewSiteVar <float>();
            ExtremeMinTemp = ModelCore.Landscape.NewSiteVar <float>();
            Landis.Utilities.Directory.EnsureExists("output");

            Timestep = ((Parameter <int>)GetParameter(Names.Timestep)).Value;
            Parameter <string> CohortBinSizeParm = null;

            if (TryGetParameter(Names.CohortBinSize, out CohortBinSizeParm))
            {
                if (Int32.TryParse(CohortBinSizeParm.Value, out CohortBinSize))
                {
                    if (CohortBinSize < Timestep)
                    {
                        throw new System.Exception("CohortBinSize cannot be smaller than Timestep.");
                    }
                    else
                    {
                        PlugIn.ModelCore.UI.WriteLine("Succession timestep = " + Timestep + "; CohortBinSize = " + CohortBinSize + ".");
                    }
                }
                else
                {
                    throw new System.Exception("CohortBinSize is not an integer value.");
                }
            }
            else
            {
                CohortBinSize = Timestep;
            }


            FTimeStep = 1.0F / Timestep;

            //Latitude = ((Parameter<float>)PlugIn.GetParameter(Names.Latitude, 0, 90)).Value; // Now an ecoregion parameter

            ObservedClimate.Initialize();

            SpeciesPnET = new SpeciesPnET();

            EcoregionPnET.Initialize();
            Hydrology.Initialize();
            SiteCohorts.Initialize();

            // John McNabb: initialize climate library after EcoregionPnET has been initialized
            InitializeClimateLibrary();

            EstablishmentProbability.Initialize(Timestep);

            IMAX = ((Parameter <ushort>)GetParameter(Names.IMAX)).Value;
            //LeakageFrostDepth = ((Parameter<float>)GetParameter(Names.LeakageFrostDepth)).Value; //Now an ecoregion parameter
            //PrecipEvents = ((Parameter<float>)GetParameter(Names.PrecipEvents)).Value;// Now an ecoregion parameter


            // Initialize Reproduction routines:
            Reproduction.SufficientResources = SufficientResources;
            Reproduction.Establish           = Establish;
            Reproduction.AddNewCohort        = AddNewCohort;
            Reproduction.MaturePresent       = MaturePresent;
            Reproduction.PlantingEstablish   = PlantingEstablish;


            SeedingAlgorithms SeedAlgorithm = (SeedingAlgorithms)Enum.Parse(typeof(SeedingAlgorithms), parameters["SeedingAlgorithm"].Value);

            base.Initialize(ModelCore, SeedAlgorithm);


            StartDate = new DateTime(((Parameter <int>)GetParameter(Names.StartYear)).Value, 1, 15);

            PlugIn.ModelCore.UI.WriteLine("Spinning up biomass or reading from maps...");

            string             InitialCommunitiesTXTFile = GetParameter(Names.InitialCommunities).Value;
            string             InitialCommunitiesMapFile = GetParameter(Names.InitialCommunitiesMap).Value;
            Parameter <string> LitterMapFile;
            bool litterMapFile = TryGetParameter(Names.LitterMap, out LitterMapFile);
            Parameter <string> WoodyDebrisMapFile;
            bool woodyDebrisMapFile = TryGetParameter(Names.WoodyDebrisMap, out WoodyDebrisMapFile);

            //Console.ReadLine();
            InitializeSites(InitialCommunitiesTXTFile, InitialCommunitiesMapFile, ModelCore);
            if (litterMapFile)
            {
                MapReader.ReadLitterFromMap(LitterMapFile.Value);
            }
            if (woodyDebrisMapFile)
            {
                MapReader.ReadWoodyDebrisFromMap(WoodyDebrisMapFile.Value);
            }

            // Convert PnET cohorts to biomasscohorts
            ISiteVar <Landis.Library.BiomassCohorts.ISiteCohorts> biomassCohorts = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.BiomassCohorts.ISiteCohorts>();


            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                biomassCohorts[site] = sitecohorts[site];

                if (sitecohorts[site] != null && biomassCohorts[site] == null)
                {
                    throw new System.Exception("Cannot convert PnET SiteCohorts to biomass site cohorts");
                }
            }
            ModelCore.RegisterSiteVar(biomassCohorts, "Succession.BiomassCohorts");
            ModelCore.RegisterSiteVar(WoodyDebris, "Succession.WoodyDebris");
            ModelCore.RegisterSiteVar(Litter, "Succession.Litter");


            ISiteVar <Landis.Library.AgeOnlyCohorts.ISiteCohorts> AgeCohortSiteVar = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.AgeOnlyCohorts.ISiteCohorts>();
            ISiteVar <ISiteCohorts> PnETCohorts = PlugIn.ModelCore.Landscape.NewSiteVar <ISiteCohorts>();


            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                AgeCohortSiteVar[site] = sitecohorts[site];
                PnETCohorts[site]      = sitecohorts[site];
                FineFuels[site]        = Litter[site].Mass;
                IEcoregionPnET ecoregion = EcoregionPnET.GetPnETEcoregion(PlugIn.ModelCore.Ecoregion[site]);
                IHydrology     hydrology = new Hydrology(ecoregion.FieldCap);
                PressureHead[site] = hydrology.GetPressureHead(ecoregion);
                if (UsingClimateLibrary)
                {
                    ExtremeMinTemp[site] = ((float)Enumerable.Min(Climate.Future_MonthlyData[Climate.Future_MonthlyData.Keys.Min()][ecoregion.Index].MonthlyTemp) - (float)(3.0 * ecoregion.WinterSTD));
                }
                else
                {
                    ExtremeMinTemp[site] = 999;
                }
            }

            ModelCore.RegisterSiteVar(AgeCohortSiteVar, "Succession.AgeCohorts");
            ModelCore.RegisterSiteVar(PnETCohorts, "Succession.CohortsPnET");
            ModelCore.RegisterSiteVar(FineFuels, "Succession.FineFuels");
            ModelCore.RegisterSiteVar(PressureHead, "Succession.PressureHead");
            ModelCore.RegisterSiteVar(ExtremeMinTemp, "Succession.ExtremeMinTemp");
        }
Esempio n. 7
0
        //---------------------------------------------------------------------
        public override void Initialize()
        {
            cohorts        = PlugIn.ModelCore.Landscape.NewSiteVar <ISiteCohorts>();
            BiomassCohorts = new BiomassCohortsSiteVar(cohorts);
            baseCohorts    = new Landis.Library.Biomass.BaseCohortsSiteVar(BiomassCohorts);

            // Counts added cohorts per site and per species
            newcohorts = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.Biomass.Species.AuxParm <int> >();
            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                newcohorts[site] = new Landis.Library.Biomass.Species.AuxParm <int>(PlugIn.ModelCore.Species);
            }


            PlugIn.ModelCore.RegisterSiteVar(NewCohorts, "Succession.NewCohorts");
            PlugIn.ModelCore.RegisterSiteVar(cohorts, "Succession.BiomassCohortsPnET");
            PlugIn.ModelCore.RegisterSiteVar(BiomassCohorts, "Succession.BiomassCohorts");

            PlugIn.ModelCore.RegisterSiteVar(baseCohorts, "Succession.AgeCohorts");

            Edu.Wisc.Forest.Flel.Util.Directory.EnsureExists("output");
            CohortOutput.Initialize(parameters);
            SiteOutput.Initialize(parameters);
            CohortBiomass.Initialize(parameters);
            EstablishmentProbability.Initialize(parameters);
            CanopyBiomass.Initialize(parameters);
            Static.Initialize(parameters);
            Hydrology.Initialize(parameters);

            Timestep = parameters.Timestep;
            tstep    = parameters.Timestep;



            // Initialize Reproduction routines:
            // Reproduction.SufficientResources = SufficientLight;
            Reproduction.Establish         = Establish;
            Reproduction.AddNewCohort      = AddNewCohort;
            Reproduction.MaturePresent     = MaturePresent;
            Reproduction.PlantingEstablish = PlantingEstablish;
            base.Initialize(modelCore, parameters.SeedAlgorithm);

            InitialBiomass.Initialize(parameters);

            Cohort.DeathEvent += CohortDied;

            // TODO ARJAN !!
            //Landis.Extension.Succession.Biomass.AgeOnlyDisturbances.Module.Initialize(parameters.AgeOnlyDisturbanceParms);

            ForestFloor.Initialize(parameters);

            SiteOutput.Initialize(parameters);



            StartDate = new System.DateTime(parameters.StartYear, 1, 15);

            year  = StartDate.Year;
            month = StartDate.Month;

            InitializeSites(parameters.InitialCommunities, parameters.InitialCommunitiesMap, modelCore);
        }
        //---------------------------------------------------------------------
        public override void Initialize()
        {
            PlugIn.ModelCore.UI.WriteLine("Initializing " + ExtensionName + " version " + typeof(PlugIn).Assembly.GetName().Version);

            /*Testing
             * Landis.Library.BiomassCohorts.Cohort C;
             * Cohort D;
             *
             * C = (Landis.Library.BiomassCohorts.Cohort)D;
             */


            hassiteoutput  = parameters.HasSiteOutput;
            siteconditions = PlugIn.ModelCore.Landscape.NewSiteVar <SiteConditions>();
            Edu.Wisc.Forest.Flel.Util.Directory.EnsureExists("output");

            //CohortOutput.Initialize(parameters);
            Hydrology.Initialize(parameters);
            StaticVariables.InitializeStatic(parameters);
            ForestFloor.Initialize(parameters);
            SiteConditions.Initialize(parameters);
            CohortBiomass.Initialize(parameters);

            Timestep = parameters.Timestep;
            tstep    = parameters.Timestep;

            // Initialize Reproduction routines:
            Reproduction.SufficientResources = SufficientResources;
            Reproduction.Establish           = Establish;
            Reproduction.AddNewCohort        = AddNewCohort;
            Reproduction.MaturePresent       = MaturePresent;
            Reproduction.PlantingEstablish   = PlantingEstablish;
            base.Initialize(modelCore, parameters.SeedAlgorithm);
            Cohort.DeathEvent += CohortDied;

            StartDate = new System.DateTime(parameters.StartYear, 1, 15);

            year  = StartDate.Year;
            month = StartDate.Month;

            InitializeSites(parameters.InitialCommunities, parameters.InitialCommunitiesMap, modelCore);

            EstablishmentProbability.Initialize(parameters);

            ISiteVar <ISiteCohorts> cohorts = PlugIn.ModelCore.Landscape.NewSiteVar <ISiteCohorts>();

            foreach (ActiveSite site in PlugIn.modelCore.Landscape)
            {
                cohorts[site] = siteconditions[site].Cohorts;
            }

            BiomassCohorts = new BiomassCohortsSiteVar(cohorts);
            baseCohorts    = new Landis.Library.Biomass.BaseCohortsSiteVar(BiomassCohorts);

            PlugIn.ModelCore.RegisterSiteVar(BiomassCohorts, "Succession.BiomassCohorts");

            PlugIn.ModelCore.RegisterSiteVar(siteconditions, "Succession.SiteConditionsPnET");
            PlugIn.ModelCore.RegisterSiteVar(baseCohorts, "Succession.AgeCohorts");


            ISiteVar <Pool> WoodyDebris = PlugIn.ModelCore.Landscape.NewSiteVar <Pool>();

            foreach (ActiveSite site in PlugIn.modelCore.Landscape)
            {
                WoodyDebris[site] = siteconditions[site].WoodyDebris;
            }
            PlugIn.ModelCore.RegisterSiteVar(WoodyDebris, "Succession.WoodyDebris");

            ISiteVar <Pool> Litter = PlugIn.ModelCore.Landscape.NewSiteVar <Pool>();

            foreach (ActiveSite site in PlugIn.modelCore.Landscape)
            {
                Litter[site] = siteconditions[site].WoodyDebris;
            }
            PlugIn.ModelCore.RegisterSiteVar(Litter, "Succession.Litter");
        }