コード例 #1
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="ActivityName"></param>
        /// <param name="Reason"></param>
        public void Add(object ResourceAmount, string ActivityName, 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.Credit       = pool.Amount;
                details.Activity     = ActivityName;
                details.Reason       = Reason;
                details.ResourceType = this.Name;
                LastTransaction      = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
コード例 #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="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);
            }
        }
コード例 #3
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);
         }
     }
 }
コード例 #4
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);
            }
        }