Пример #1
0
        private void OnGraze(GrazeType GrazeData)
        {
            if ((!isAlive) || StandingWt == 0)
                return;

            // Get the amount that can potentially be removed
            double amountRemovable = mySward.Sum(mySpecies => mySpecies.HarvestableWt);

            // get the amount required to remove
            double amountRequired = 0.0;
            if (GrazeData.type.ToLower() == "SetResidueAmount".ToLower())
            { // Remove all DM above given residual amount
                amountRequired = Math.Max(0.0, StandingWt - GrazeData.amount);
            }
            else if (GrazeData.type.ToLower() == "SetRemoveAmount".ToLower())
            { // Attempt to remove a given amount
                amountRequired = Math.Max(0.0, GrazeData.amount);
            }
            else
            {
                Console.WriteLine("  AgPasture - Method to set amount to remove not recognized, command will be ignored");
            }
            // get the actual amount to remove
            double amountToRemove = Math.Min(amountRequired, amountRemovable);

            // get the amounts to remove by mySpecies:
            if (amountRequired > 0.0)
            {
                // get the weights for each mySpecies, consider preference and available DM
                double[] tempWeights = new double[numSpecies];
                double[] tempAmounts = new double[numSpecies];
                double tempTotal = 0.0;
                double totalPreference = mySward.Sum(mySpecies => mySpecies.PreferenceForGreenDM + mySpecies.PreferenceForDeadDM);
                for (int s = 0; s < numSpecies; s++)
                {
                    tempWeights[s] = mySward[s].PreferenceForGreenDM + mySward[s].PreferenceForDeadDM;
                    tempWeights[s] += (totalPreference - tempWeights[s]) * (amountToRemove / amountRemovable);
                    tempAmounts[s] = Math.Max(0.0, mySward[s].StandingLiveWt - mySward[s].MinimumGreenWt)
                                   + Math.Max(0.0, mySward[s].StandingDeadWt - mySward[s].MinimumDeadWt);
                    tempTotal += tempAmounts[s] * tempWeights[s];
                }

                // do the actual removal for each mySpecies
                for (int s = 0; s < numSpecies; s++)
                {
                    // get the actual fractions to remove for each mySpecies
                    if (tempTotal > 0.0)
                        mySward[s].fractionHarvested = Math.Max(0.0, Math.Min(1.0, tempWeights[s] * tempAmounts[s] / tempTotal));
                    else
                        mySward[s].fractionHarvested = 0.0;

                    // remove DM and N for each mySpecies (digestibility is also evaluated)
                    mySward[s].RemoveDM(amountToRemove * mySward[s].HarvestedFraction);
                }
            }
        }
Пример #2
0
 /// <summary>Harvest (remove DM) the sward</summary>
 /// <param name="amount">DM amount</param>
 /// <param name="type">How the amount is interpreted (remove or residual)</param>
 public void Harvest(double amount, string type)
 {
     GrazeType GrazeData = new GrazeType();
     GrazeData.amount = amount;
     GrazeData.type = type;
     OnGraze(GrazeData);
 }
Пример #3
0
 private void OnGraze(GrazeType GZ)
 {
     Graze(GZ.type, GZ.amount);
 }
Пример #4
0
        private void OnGraze(GrazeType GrazeData)
        {
            if ((!isAlive) || StandingWt == 0)
                return;

            // get the amount required to remove
            double amountRequired = 0.0;
            if (GrazeData.type.ToLower() == "SetResidueAmount".ToLower())
            { // Remove all DM above given residual amount
                amountRequired = Math.Max(0.0, StandingWt - GrazeData.amount);
            }
            else if (GrazeData.type.ToLower() == "SetRemoveAmount".ToLower())
            { // Attempt to remove a given amount
                amountRequired = Math.Max(0.0, GrazeData.amount);
            }
            else
            {
                Console.WriteLine("  AgPasture - Method to set amount to remove not recognized, command will be ignored");
            }
            // get the actual amount to remove
            double amountToRemove = Math.Min(amountRequired, HarvestableWt);

            // Do the actual removal
            if (amountRequired > 0.0)
                RemoveDM(amountToRemove);
        }
Пример #5
0
 //Being called not by Event
 //----------------------------------------------------------------------
 /// <summary>Harvests the specified type.</summary>
 /// <param name="type">The type.</param>
 /// <param name="amount">The amount.</param>
 public void Harvest(String type, double amount)
 {
     GrazeType GZ = new GrazeType();
     GZ.amount = amount;
     GZ.type = type;
     OnGraze(GZ);
 }