Beispiel #1
0
 /// <summary>
 /// Return the specified pool
 /// </summary>
 /// <param name="index">index to use</param>
 /// <param name="getByAge">return where index is age</param>
 /// <returns>GraxeFoodStore pool</returns>
 public GrazeFoodStorePool Pool(int index, bool getByAge)
 {
     if (getByAge)
     {
         var res = Pools.Where(a => a.Age == index);
         if (res.Count() > 1)
         {
             // return an average pool for N and DMD
             GrazeFoodStorePool average = new GrazeFoodStorePool()
             {
                 Age      = index,
                 Consumed = res.Sum(a => a.Consumed),
                 Detached = res.Sum(a => a.Detached),
                 Growth   = res.Sum(a => a.Growth),
                 DMD      = res.Sum(a => a.DMD * a.Amount) / res.Sum(a => a.Amount),
                 Nitrogen = res.Sum(a => a.Nitrogen * a.Amount) / res.Sum(a => a.Amount)
             };
             average.Set(res.Sum(a => a.Amount));
             return(average);
         }
         else
         {
             return(res.FirstOrDefault());
         }
     }
     else
     if (index < Pools.Count())
     {
         return(Pools[index]);
     }
     else
     {
         return(null);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="reason">Name of individual adding resource</param>
        public new void Add(object resourceAmount, CLEMModel activity, string reason)
        {
            GrazeFoodStorePool pool;

            switch (resourceAmount.GetType().Name)
            {
            case "GrazeFoodStorePool":
                pool = resourceAmount as GrazeFoodStorePool;
                break;

            case "FoodResourcePacket":
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
                break;

            case "Double":
                pool = new GrazeFoodStorePool();
                pool.Set((double)resourceAmount);
                pool.Nitrogen = this.Nitrogen;
                pool.DMD      = this.EstimateDMD(this.Nitrogen);
                break;

            default:
                // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage) or Double from G-Range
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            if (pool.Amount > 0)
            {
                // allow decaying or no pools currently available
                if (PastureDecays || Pools.Count() == 0)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    Pools[0].Add(pool);
                }
                // update biomass available
                biomassAddedThisYear += pool.Amount;

                ResourceTransaction details = new ResourceTransaction
                {
                    Gain         = pool.Amount,
                    Activity     = activity,
                    Reason       = reason,
                    ResourceType = this
                };
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage)
            if (!(resourceAmount.GetType() == typeof(GrazeFoodStorePool) || resourceAmount.GetType() != typeof(FoodResourcePacket)))
            {
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            GrazeFoodStorePool pool;

            if (resourceAmount.GetType() == typeof(GrazeFoodStorePool))
            {
                pool = resourceAmount as GrazeFoodStorePool;
            }
            else
            {
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
            }

            if (pool.Amount > 0)
            {
                // need to check the follwoing code is no longer needed.

                // allow decaying or no pools currently available
                //if (PastureDecays || Pools.Count() == 0)
                //{
                //    Pools.Insert(0, pool);
                //}
                //else
                //{
                //    Pools[0].Add(pool);
                //}
                //// update biomass available
                //biomassAddedThisYear += pool.Amount;

                ResourceTransaction details = new ResourceTransaction
                {
                    TransactionType   = TransactionType.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    Category          = category,
                    RelatesToResource = relatesToResource,
                    ResourceType      = this
                };
                LastGain        = pool.Amount;
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="reason">Name of individual adding resource</param>
        public new void Add(object resourceAmount, CLEMModel activity, string reason)
        {
            // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage)
            if (!(resourceAmount.GetType() == typeof(GrazeFoodStorePool) || resourceAmount.GetType() == typeof(FoodResourcePacket)))
            {
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            GrazeFoodStorePool pool;

            if (resourceAmount.GetType() == typeof(GrazeFoodStorePool))
            {
                pool = resourceAmount as GrazeFoodStorePool;
            }
            else
            {
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
            }

            if (pool.Amount > 0)
            {
                // allow decaying or no pools currently available
                if (PastureDecays || Pools.Count() == 0)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    Pools[0].Add(pool);
                }
                // update biomass available
                biomassAddedThisYear += pool.Amount;

                ResourceTransaction details = new ResourceTransaction();
                details.Gain         = pool.Amount;
                details.Activity     = activity.Name;
                details.ActivityType = activity.GetType().Name;
                details.Reason       = reason;
                details.ResourceType = this.Name;
                LastTransaction      = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Add to Resource method.
 /// This style is used when a pool needs to be added to the current pool
 /// This occurs when no detachment and decay (values of zero) are included in the GrazeFoodStore parameters
 /// </summary>
 /// <param name="pool">GrazeFoodStorePool to add to this pool</param>
 public void Add(GrazeFoodStorePool pool)
 {
     if (pool.Amount > 0)
     {
         // adjust DMD and N% based on incoming if needed
         if (DMD != pool.DMD || Nitrogen != pool.Nitrogen)
         {
             //TODO: run calculation passed others.
             DMD      = ((DMD * Amount) + (pool.DMD * pool.Amount)) / (Amount + pool.Amount);
             Nitrogen = ((Nitrogen * Amount) + (pool.Nitrogen * pool.Amount)) / (Amount + pool.Amount);
         }
         amount += pool.Amount;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage)
            if (!(resourceAmount.GetType() == typeof(GrazeFoodStorePool) || resourceAmount.GetType() != typeof(FoodResourcePacket)))
            {
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            GrazeFoodStorePool pool;

            if (resourceAmount.GetType() == typeof(GrazeFoodStorePool))
            {
                pool = resourceAmount as GrazeFoodStorePool;
            }
            else
            {
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
            }

            if (pool.Amount > 0)
            {
                ResourceTransaction details = new ResourceTransaction
                {
                    TransactionType   = TransactionType.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    Category          = category,
                    RelatesToResource = relatesToResource,
                    ResourceType      = this
                };
                LastGain        = pool.Amount;
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            GrazeFoodStorePool pool;

            switch (resourceAmount.GetType().Name)
            {
            case "GrazeFoodStorePool":
                pool = resourceAmount as GrazeFoodStorePool;
                // adjust N content only if new growth (age = 0) based on yield limits and month range defined in GrazeFoodStoreFertilityLimiter if present
                if (pool.Age == 0 && !(grazeFoodStoreFertilityLimiter is null))
                {
                    double reduction = grazeFoodStoreFertilityLimiter.GetProportionNitrogenLimited(pool.Amount / Manager.Area);
                    pool.Nitrogen = Math.Max(MinimumNitrogen, pool.Nitrogen * reduction);
                }
                break;

            case "FoodResourcePacket":
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
                break;

            case "Double":
                pool = new GrazeFoodStorePool();
                pool.Set((double)resourceAmount);
                pool.Nitrogen = this.Nitrogen;
                pool.DMD      = this.EstimateDMD(this.Nitrogen);
                break;

            default:
                // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage) or Double from G-Range
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }
            if (pool.Amount > 0)
            {
                // allow decaying or no pools currently available
                if (PastureDecays || Pools.Count() == 0)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    Pools[0].Add(pool);
                }
                // update biomass available
                if (!category.StartsWith("Initialise"))
                {
                    // do not update if this is ian initialisation pool
                    biomassAddedThisYear += pool.Amount;
                }

                ResourceTransaction details = new ResourceTransaction
                {
                    Style             = TransactionStyle.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    RelatesToResource = relatesToResource,
                    Category          = category,
                    ResourceType      = this
                };
                LastTransaction = details;
                LastGain        = pool.Amount;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }