Beispiel #1
0
        //---------------------------------------------------------------------

        public static void WriteTotalsFor(ActiveSite site)
        {
            logFile.Write("{0},{1},{2}", Model.Core.CurrentTime, site.Location.Row, site.Location.Column);
            foreach (ISpecies species in Model.Core.Species)
            {
                logFile.Write(",{0}", SiteBiomass.Harvested[species]);
            }
            logFile.WriteLine();
            SiteBiomass.ResetHarvestTotals();
        }
        //---------------------------------------------------------------------

        public static void Initialize(string path)
        {
            Model.Core.UI.WriteLine("  Opening log file \"{0}\"...", path);
            logFile = Landis.Data.CreateTextFile(path);
            logFile.Write("timestep,row,column");
            foreach (ISpecies species in Model.Core.Species)
            {
                logFile.Write(",{0}", species.Name);
            }
            logFile.WriteLine();
            Enabled = true;
            SiteBiomass.ResetHarvestTotals();
        }
Beispiel #3
0
        //---------------------------------------------------------------------

        // Event handler when a site has been harvested.
        public static void SiteHarvested(object sender,
                                         SiteHarvestedEvent.Args eventArgs)
        {
            ActiveSite site = eventArgs.Site;
            IDictionary <ISpecies, int> biomassBySpecies = new Dictionary <ISpecies, int>();

            foreach (ISpecies species in ModelCore.Species)
            {
                int speciesBiomassHarvested = SiteBiomass.Harvested[species];
                SiteVars.BiomassRemoved[site] += speciesBiomassHarvested;
                biomassBySpecies.Add(species, speciesBiomassHarvested);
            }
            SiteVars.BiomassBySpecies[site] = biomassBySpecies;
            SiteBiomass.ResetHarvestTotals();
        }
Beispiel #4
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Clean up at the end of the extension's execution during the current
        /// timestep.
        /// </summary>
        public static void TimestepTearDown()
        {
            SiteBiomass.DisableRecordingForHarvest();
        }
Beispiel #5
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Prepare the log file for the extension's execution during current
        /// timestep.
        /// </summary>
        public static void TimestepSetUp()
        {
            SiteBiomass.EnableRecordingForHarvest();
        }
Beispiel #6
0
        //---------------------------------------------------------------------

        public override void Run()
        {
            running = true;

            HarvestMgmtLib.SiteVars.Prescription.ActiveSiteValues = null;
            SiteVars.BiomassRemoved.ActiveSiteValues = 0;
            Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged.ActiveSiteValues = 0;
            HarvestMgmtLib.SiteVars.CohortsDamaged.ActiveSiteValues = 0;
            SiteVars.BiomassBySpecies.ActiveSiteValues = null;

            SiteBiomass.EnableRecordingForHarvest();

            //harvest each management area in the list
            foreach (ManagementArea mgmtArea in managementAreas)
            {
                totalSites          = new int[Prescription.Count];
                totalDamagedSites   = new int[Prescription.Count];
                totalSpeciesCohorts = new int[Prescription.Count, modelCore.Species.Count];
                totalCohortsDamaged = new int[Prescription.Count];
                totalCohortsKilled  = new int[Prescription.Count];
                // 2015-09-14 LCB Track prescriptions as they are reported in summary log so we don't duplicate
                prescriptionReported = new bool[Prescription.Count];
                totalSpeciesBiomass  = new double[Prescription.Count, modelCore.Species.Count];
                totalBiomassRemoved  = new double[Prescription.Count];

                mgmtArea.HarvestStands();
                //and record each stand that's been harvested

                foreach (Stand stand in mgmtArea)
                {
                    //ModelCore.UI.WriteLine("   List of stands {0} ...", stand.MapCode);
                    if (stand.Harvested)
                    {
                        WriteLogEntry(mgmtArea, stand);
                    }
                }

                // Prevent establishment:
                foreach (Stand stand in mgmtArea)
                {
                    if (stand.Harvested && stand.LastPrescription.PreventEstablishment)
                    {
                        List <ActiveSite> sitesToDelete = new List <ActiveSite>();

                        foreach (ActiveSite site in stand)
                        {
                            if (Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged[site] > 0 || HarvestMgmtLib.SiteVars.CohortsDamaged[site] > 0)
                            {
                                Landis.Library.Succession.Reproduction.PreventEstablishment(site);
                                sitesToDelete.Add(site);
                            }
                        }

                        foreach (ActiveSite site in sitesToDelete)
                        {
                            stand.DelistActiveSite(site);
                        }
                    }
                }

                // Write Summary Log File:
                foreach (AppliedPrescription aprescription in mgmtArea.Prescriptions)
                {
                    Prescription prescription    = aprescription.Prescription;
                    double[]     species_cohorts = new double[modelCore.Species.Count];
                    double[]     species_biomass = new double[modelCore.Species.Count];
                    foreach (ISpecies species in modelCore.Species)
                    {
                        species_cohorts[species.Index] = totalSpeciesCohorts[prescription.Number, species.Index];
                        species_biomass[species.Index] = totalSpeciesBiomass[prescription.Number, species.Index];
                    }

                    if (totalSites[prescription.Number] > 0 && prescriptionReported[prescription.Number] != true)
                    {
                        summaryLog.Clear();
                        SummaryLog sl = new SummaryLog();
                        sl.Time                        = modelCore.CurrentTime;
                        sl.ManagementArea              = mgmtArea.MapCode;
                        sl.Prescription                = prescription.Name;
                        sl.HarvestedSites              = totalDamagedSites[prescription.Number];
                        sl.TotalBiomassHarvested       = totalBiomassRemoved[prescription.Number];
                        sl.TotalCohortsPartialHarvest  = totalCohortsDamaged[prescription.Number];
                        sl.TotalCohortsCompleteHarvest = totalCohortsKilled[prescription.Number];
                        sl.CohortsHarvested_           = species_cohorts;
                        sl.BiomassHarvestedMg_         = species_biomass;
                        summaryLog.AddObject(sl);
                        summaryLog.WriteToFile();

                        prescriptionReported[prescription.Number] = true;
                    }
                }
            }

            WritePrescriptionMap(modelCore.CurrentTime);
            if (biomassMaps != null)
            {
                biomassMaps.WriteMap(modelCore.CurrentTime);
            }

            running = false;

            SiteBiomass.DisableRecordingForHarvest();
        }
        //---------------------------------------------------------------------

        public override void Run()
        {
            running = true;

            HarvestMgmtLib.SiteVars.Prescription.ActiveSiteValues = null;
            SiteVars.BiomassRemoved.ActiveSiteValues = 0;
            Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged.ActiveSiteValues = 0;
            HarvestMgmtLib.SiteVars.CohortsDamaged.ActiveSiteValues = 0;
            SiteVars.BiomassBySpecies.ActiveSiteValues = null;

            SiteBiomass.EnableRecordingForHarvest();

            //harvest each management area in the list
            foreach (ManagementArea mgmtArea in managementAreas)
            {
                totalSites          = new int[Prescription.Count];
                totalDamagedSites   = new int[Prescription.Count];
                totalSpeciesCohorts = new int[Prescription.Count, modelCore.Species.Count];
                totalCohortsDamaged = new int[Prescription.Count];
                totalCohortsKilled  = new int[Prescription.Count];
                // 2015-09-14 LCB Track prescriptions as they are reported in summary log so we don't duplicate
                prescriptionReported = new bool[Prescription.Count];
                totalSpeciesBiomass  = new double[Prescription.Count, modelCore.Species.Count];
                totalBiomassRemoved  = new double[Prescription.Count];

                mgmtArea.HarvestStands();
                //and record each stand that's been harvested in a non-repeat step

                foreach (Stand stand in mgmtArea)
                {
                    //ModelCore.UI.WriteLine("   List of stands {0} ...", stand.MapCode);
                    if (stand.Harvested && !stand.RepeatHarvested)
                    {
                        WriteLogEntry(mgmtArea, stand);
                    }

                    // Do not double up on recording repeat harvested stands. This is now done from the harvest code
                    else if (stand.RepeatHarvested)
                    {
                        stand.SetRepeatHarvested();
                    }
                }

                // Prevent establishment:
                foreach (Stand stand in mgmtArea)
                {
                    if (stand.Harvested && stand.LastPrescription.PreventEstablishment)
                    {
                        List <ActiveSite> sitesToDelete = new List <ActiveSite>();

                        foreach (ActiveSite site in stand)
                        {
                            if (Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged[site] > 0 || HarvestMgmtLib.SiteVars.CohortsDamaged[site] > 0)
                            {
                                Landis.Library.Succession.Reproduction.PreventEstablishment(site);
                                sitesToDelete.Add(site);
                            }
                        }

                        foreach (ActiveSite site in sitesToDelete)
                        {
                            stand.DelistActiveSite(site);
                        }
                    }
                }

                foreach (AppliedPrescription aprescription in mgmtArea.Prescriptions)
                {
                    if (modelCore.CurrentTime <= aprescription.EndTime)
                    {
                        WriteSummaryLogEntry(mgmtArea, aprescription);
                    }
                }
            }

            WritePrescriptionMap(modelCore.CurrentTime);
            if (biomassMaps != null)
            {
                biomassMaps.WriteMap(modelCore.CurrentTime);
            }

            running = false;

            SiteBiomass.DisableRecordingForHarvest();
        }