Example #1
0
 /// <summary>
 /// Transfers the specified source.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <param name="srcIdx">Index of the source.</param>
 /// <param name="dest">The dest.</param>
 /// <param name="destIdx">Index of the dest.</param>
 /// <param name="amount">The amount.</param>
 /// <exception cref="System.Exception">Invalid transfer of feed</exception>
 private void Transfer(TSupplementRation src, int srcIdx, TSupplementRation dest, int destIdx, double amount)
 {
     if (srcIdx < 0 || srcIdx >= src.Count || destIdx < 0 || destIdx > dest.Count)
     {
         throw new Exception("Invalid transfer of feed");
     }
     if (src[srcIdx].Amount > 0)
     {
         if (amount > 0.0)
         {
             if (destIdx < dest.Count)
             {
                 SuppIntoRation(dest, destIdx, src[srcIdx], amount);
             }
             else
             {
                 TSupplement copy = new TSupplement();
                 copy.Assign(src[srcIdx]);
                 dest.Add(copy, amount);
             }
             src[srcIdx].Amount -= amount;
         }
     }
     else
     {
         dest[destIdx].Amount = 0;
     }
 }
Example #2
0
        /// <summary>
        /// Blends the specified source store.
        /// </summary>
        /// <param name="srcStore">The source store.</param>
        /// <param name="transferKg">The transfer kg.</param>
        /// <param name="destStore">The dest store.</param>
        /// <exception cref="System.Exception">Supplement \ + srcStore + \ not recognised</exception>
        public void Blend(string srcStore, double transferKg, string destStore)
        {
            int iSrc = IndexOf(srcStore);

            if (iSrc < 0)
            {
                throw new Exception("Supplement \"" + srcStore + "\" not recognised");
            }

            transferKg = System.Math.Min(transferKg, this[iSrc].Amount);
            if (transferKg > 0.0)
            {
                int iDest = IndexOf(destStore);
                if (iDest < 0)
                {
                    TSupplement newSupp = new TSupplement();
                    newSupp.Assign(this[iSrc]);
                    newSupp.sName = destStore;
                    iDest         = AddToStore(0.0, newSupp);
                }
                Transfer(this, iSrc, this, iDest, transferKg);
            }
        }
Example #3
0
        /// <summary>
        /// Adds an amount of a supplement to a store.
        /// * If the store name already exists in the FStores array, the method adds
        /// the supplement to that store.  Otherwise a new store is created.
        /// * The DMP, DMD, MEDM, CP, DG, EE and ADIP2CP parameters may be set to zero,
        /// in which case the default values for the supplement name are used.
        /// Defaults are taken from the current store if the name is already defined,
        /// and from grazSUPP.PAS otherwise.  If defaults cannot be found for a name,
        /// wheat is used as the default composition.
        /// </summary>
        /// <param name="suppKg">Amount (kg fresh weight) of the supplement to be included in the store.</param>
        /// <param name="suppName">Name of the supplement.</param>
        /// <param name="roughage">The roughage.</param>
        /// <param name="DMP">Proportion of the fresh weight which is dry matter   kg/kg FW</param>
        /// <param name="DMD">Dry matter digestibility of the supplement           kg/kg DM</param>
        /// <param name="MEDM">Metabolisable energy content of dry matter           MJ/kg DM</param>
        /// <param name="CP">Crude protein content                                kg/kg DM</param>
        /// <param name="DG">Degradability of the crude protein                   kg/kg CP</param>
        /// <param name="EE">Ether-extractable content                            kg/kg DM</param>
        /// <param name="ADIP2CP">Ratio of acid detergent insoluble protein to CP      kg/kg CP</param>
        /// <param name="phos">Phosphorus content                                   kg/kg DM</param>
        /// <param name="sulf">Sulphur content                                      kg/kg DM</param>
        /// <param name="ashAlk">Ash alkalinity                                       mol/kg DM</param>
        /// <param name="maxPass">Maximum passage rate                                 0-1</param>
        /// <returns>
        /// Index of the supplement in the store
        /// </returns>
        public int AddToStore(double suppKg, string suppName, int roughage = DEFAULT, double DMP = 0.0, double DMD = 0.0,
                              double MEDM = 0.0, double CP   = 0.0, double DG     = 0.0, double EE      = 0.0, double ADIP2CP = 0.0,
                              double phos = 0.0, double sulf = 0.0, double ashAlk = 0.0, double maxPass = 0.0)
        {
            int idx = IndexOf(suppName);

            TSupplement addSupp = new TSupplement(suppName);

            if (idx >= 0)                             // Work out the composition of the supplement being added
            {
                addSupp.Assign(this[idx]);
            }
            else
            {
                addSupp.DefaultFromName();
            }
            addSupp.sName = suppName.ToLower();

            if (roughage == ROUGHAGE)                 // Override the default composition as required
            {
                addSupp.IsRoughage = true;
            }
            else if (roughage != DEFAULT)
            {
                addSupp.IsRoughage = false;
            }

            if (DMP > 0.0)
            {
                addSupp.DM_Propn = DMP;
            }
            if (DMD > 0.0)
            {
                addSupp.DM_Digestibility = DMD;
            }
            if (MEDM > 0.0)
            {
                addSupp.ME_2_DM = MEDM;
            }
            if (CP > 0.0)
            {
                addSupp.CrudeProt = CP;
            }
            if (DG > 0.0)
            {
                addSupp.DgProt = DG;
            }
            if (EE > 0.0)
            {
                addSupp.EtherExtract = EE;
            }
            if (ADIP2CP > 0.0)
            {
                addSupp.ADIP_2_CP = ADIP2CP;
            }
            if (phos > 0.0)
            {
                addSupp.Phosphorus = phos;
            }
            if (sulf > 0.0)
            {
                addSupp.Sulphur = sulf;
            }
            if (ashAlk > 0.0)
            {
                addSupp.AshAlkalinity = ashAlk;
            }
            if (maxPass > 0.0)
            {
                addSupp.MaxPassage = maxPass;
            }

            if (DMD > 0.0 && MEDM == 0.0)
            {
                addSupp.ME_2_DM = addSupp.DefaultME2DM();
            }
            else if (DMD == 0.0 && MEDM > 0.0)
            {
                addSupp.DM_Digestibility = addSupp.DefaultDMD();
            }

            return(AddToStore(suppKg, addSupp));
        }