Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TSupplementModel"/> class.
 /// </summary>
 public TSupplementModel()
     : base()
 {
     AddToStore(0.0, FODDER, ROUGHAGE);
     fSuppts[0].DM_Propn = 0.85;
     FCurrPaddSupp       = new TSupplement();
 }
Beispiel #2
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;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Supps the into ration.
 /// </summary>
 /// <param name="ration">The ration.</param>
 /// <param name="idx">The index.</param>
 /// <param name="supp">The supp.</param>
 /// <param name="amount">The amount.</param>
 private void SuppIntoRation(TSupplementRation ration, int idx, TSupplement supp, double amount)
 {
     if (amount > 0.0)
     {
         double propn = amount / (amount + ration[idx].Amount);
         ration[idx].Mix(supp, ration[idx], propn);
         ration[idx].Amount += amount;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Adds the fodder.
        /// </summary>
        /// <param name="destStore">The dest store.</param>
        /// <param name="fodderFW">The fodder fw.</param>
        /// <param name="DMP">The DMP.</param>
        /// <param name="DMD">The DMD.</param>
        /// <param name="NConc">The n conc.</param>
        /// <param name="PConc">The p conc.</param>
        /// <param name="SConc">The s conc.</param>
        /// <param name="ashAlk">The ash alk.</param>
        public void AddFodder(string destStore, double fodderFW, double DMP, double DMD, double NConc,
                              double PConc, double SConc, double ashAlk)
        {
            if (string.IsNullOrWhiteSpace(destStore))
            {
                destStore = FODDER;
            }

            double protDg  = System.Math.Min(0.9, DMD + 0.1);
            double ADIP2CP = 0.19 * (1.0 - protDg);
            double EE      = 0.02;
            double MEDM    = TSupplement.ConvertDMD_To_ME2DM(DMD, true, EE);

            AddToStore(fodderFW, destStore, ROUGHAGE, DMP, DMD, MEDM, TSupplement.N2PROTEIN * NConc, protDg, EE, ADIP2CP,
                       PConc, SConc, ashAlk, 0.0);
        }
Beispiel #5
0
        /// <summary>
        /// Adds to store.
        /// </summary>
        /// <param name="suppKg">The supp kg.</param>
        /// <param name="suppComp">The supp comp.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Supplement submodel: cannot combine roughage and concentrate, both named  + suppComp.sName</exception>
        public int AddToStore(double suppKg, TSupplement suppComp)
        {
            int suppIdx = IndexOf(suppComp.sName);

            if (suppIdx < 0)
            {
                suppIdx = Add(suppComp, suppKg);
            }
            else if (suppKg > 0.0)
            {
                if (suppComp.IsRoughage != fSuppts[suppIdx].IsRoughage)
                {
                    throw new Exception("Supplement submodel: cannot combine roughage and concentrate, both named " + suppComp.sName);
                }
                SuppIntoRation(this, suppIdx, suppComp, suppKg);
            }
            return(suppIdx);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
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));
        }
Beispiel #8
0
 /// <summary>
 /// Adds the specified TSupplement.
 /// </summary>
 /// <param name="supplement">Supplement to be added</param>
 /// <returns>Index of the added supplement</returns>
 public int Add(TSupplement supplement)
 {
     return(theModel.AddToStore(0.0, supplement));
 }