/// <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; } }
/// <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; } }
/// <summary> /// Completes the time step. /// </summary> public void CompleteTimeStep() { int lastDay = (int)(SpoilageTime - 1.0e-6); for (int iPadd = 0; iPadd < Paddocks.Length; iPadd++) { TSupplementRation ration = Paddocks[iPadd].SupptFed; if (ration.Count > 0) { for (int iDay = System.Math.Min(lastDay, ration.Count); iDay > 0; iDay--) { ration[iDay] = ration[iDay - 1]; ration[iDay].Amount = ration[iDay - 1].Amount * (SpoilageTime - iDay) / (SpoilageTime - (iDay - 1)); } ration[0].Amount = 0.0; } } }
/// <summary> /// Removes the suppt. /// </summary> /// <param name="paddIdx">Index of the padd.</param> /// <param name="suppKg">The supp kg.</param> /// <exception cref="System.Exception">Paddock not recognised</exception> private void RemoveSuppt(int paddIdx, double suppKg) { if (paddIdx < 0) { throw new Exception("Paddock not recognised"); } TSupplementRation ration = Paddocks[paddIdx].SupptFed; if (suppKg > 0.0 && ration.TotalAmount > 0.0) { double removePropn = suppKg / ration.TotalAmount; if (removePropn < 1.0 - 1.0e-6) { ration.TotalAmount -= suppKg; } else { ration.TotalAmount = 0.0; } } }