Ejemplo n.º 1
0
        /// <summary>Harvest the crop.</summary>
        public void RemoveBiomass(string biomassRemoveType, RemovalFractions removalData = null)
        {
            // Set up the default BiomassRemovalData values
            RemovingBiomassArgs allData = new RemovingBiomassArgs();

            allData.biomassRemoveType = biomassRemoveType;
            foreach (IOrgan organ in Organs)
            {
                OrganBiomassRemovalType biomassRemoved = Apsim.Get(organ as IModel, "BiomassRemovalDefaults." + biomassRemoveType) as OrganBiomassRemovalType;
                if (biomassRemoved == null)
                {
                    throw new Exception("Cannot find biomass removal defaults: " + organ.Name + ".BiomassRemovalDefaults.Harvest");
                }

                // Override the defaults if values were supplied as arguments.
                if (removalData != null)
                {
                    OrganBiomassRemovalType userFractions = removalData.GetFractionsForOrgan(organ.Name);
                    if (userFractions != null)
                    {
                        if (userFractions.FractionRemoved >= 0)
                        {
                            biomassRemoved.FractionRemoved = userFractions.FractionRemoved;
                        }
                        if (userFractions.FractionToResidue >= 0)
                        {
                            biomassRemoved.FractionToResidue = userFractions.FractionToResidue;
                        }
                    }
                }
                allData.removalData.Add(organ.Name, biomassRemoved);
            }

            Summary.WriteMessage(this, string.Format("Biomass removed from crop " + Name + " by " + biomassRemoveType + "ing"));

            // Invoke an event.
            if (biomassRemoveType == "Harvest" && Harvesting != null)
            {
                Harvesting.Invoke(this, new EventArgs());
            }
            else if (RemovingBiomass != null)
            {
                RemovingBiomass.Invoke(this, allData);
            }

            // Remove the biomass
            foreach (IOrgan organ in Organs)
            {
                organ.DoRemoveBiomass(allData.removalData[organ.Name]);
            }

            // Reset the phenology if SetPhenologyStage specified.
            if (removalData != null && removalData.SetPhenologyStage != 0)
            {
                Phenology.ReSetToStage(removalData.SetPhenologyStage);
            }

            // Reduce plant and stem population if thinning proportion specified
            if (removalData != null && removalData.SetThinningProportion != 0)
            {
                Structure.doThin(removalData.SetThinningProportion);
            }
        }
Ejemplo n.º 2
0
        /// <summary>Harvest the crop.</summary>
        public void RemoveBiomass(string biomassRemoveType, RemovalFractions removalData = null)
        {
            // Set up the default BiomassRemovalData values
            RemovingBiomassArgs allData = new RemovingBiomassArgs();
            allData.biomassRemoveType = biomassRemoveType;
            foreach (IOrgan organ in Organs)
            {
                // Get the default removal fractions
                OrganBiomassRemovalType biomassRemoval = Apsim.Get(organ as IModel, "BiomassRemovalDefaults." + biomassRemoveType) as OrganBiomassRemovalType;
                if (biomassRemoval == null)
                    throw new Exception("Cannot find biomass removal defaults: " + organ.Name + ".BiomassRemovalDefaults." + biomassRemoveType);

                // Override the defaults if values were supplied as arguments
                if (removalData != null)
                {
                    OrganBiomassRemovalType userFractions = removalData.GetFractionsForOrgan(organ.Name);
                    if (userFractions != null)
                    {
                        if(!MathUtilities.FloatsAreEqual(userFractions.FractionLiveToRemove, biomassRemoval.FractionLiveToRemove, 1E-9))
                            biomassRemoval.FractionLiveToRemove = userFractions.FractionLiveToRemove;
                        if (!MathUtilities.FloatsAreEqual(userFractions.FractionDeadToRemove, biomassRemoval.FractionDeadToRemove, 1E-9))
                            biomassRemoval.FractionDeadToRemove = userFractions.FractionDeadToRemove;
                        if (!MathUtilities.FloatsAreEqual(userFractions.FractionLiveToResidue, biomassRemoval.FractionLiveToResidue, 1E-9))
                            biomassRemoval.FractionLiveToResidue = userFractions.FractionLiveToResidue;
                        if (!MathUtilities.FloatsAreEqual(userFractions.FractionDeadToResidue, biomassRemoval.FractionDeadToResidue, 1E-9))
                            biomassRemoval.FractionDeadToResidue = userFractions.FractionDeadToResidue;
                    }
                }
                allData.removalData.Add(organ.Name, biomassRemoval);
            }

            Summary.WriteMessage(this, string.Format("Biomass removed from crop " + Name + " by " + biomassRemoveType + "ing"));

            // Invoke an event.
            if (biomassRemoveType == "Harvest" && Harvesting != null)
                Harvesting.Invoke(this, new EventArgs());
            else if (RemovingBiomass != null)
                RemovingBiomass.Invoke(this, allData);

            // Remove the biomass
            foreach (IOrgan organ in Organs)
            {
                organ.DoRemoveBiomass(allData.removalData[organ.Name]);
            }

            // Reset the phenology if SetPhenologyStage specified.
            if (removalData != null && removalData.SetPhenologyStage != 0)
                Phenology.ReSetToStage(removalData.SetPhenologyStage);

            // Reduce plant and stem population if thinning proportion specified
            if (removalData != null && removalData.SetThinningProportion != 0)
                Structure.doThin(removalData.SetThinningProportion);
        }