Exemplo n.º 1
0
        /// <summary>
        /// Populate the dry matter pool
        /// </summary>
        /// <param name="model">The stock model</param>
        /// <param name="propCode">The property code</param>
        /// <param name="useYoung">For young</param>
        /// <param name="useAll">For all groups</param>
        /// <param name="useTag">For tag number</param>
        /// <param name="poolValues">The DM pool value returned</param>
        /// <returns>True if the propCode is valid</returns>
        public static bool PopulateDMPoolValue(StockList model, int propCode, bool useYoung, bool useAll, bool useTag, ref DMPoolHead[] poolValues)
        {
            int         numPasses;
            AnimalGroup animalGroup;

            GrazType.DM_Pool pool      = new GrazType.DM_Pool();
            GrazType.DM_Pool totalPool = new GrazType.DM_Pool();
            int denom;
            int passIdx, idx;

            bool result = true;

            for (int i = 0; i < poolValues.Length; i++)
            {
                poolValues[i] = new DMPoolHead();
            }

            if (useTag)
            {
                numPasses = poolValues.Length;
            }
            else
            {
                numPasses = 1;
            }

            for (passIdx = 1; passIdx <= numPasses; passIdx++)
            {
                GrazType.ZeroDMPool(ref totalPool);
                denom = 0;

                for (idx = 1; idx <= model.Count(); idx++)
                {
                    if (!useTag || (model.GetTag(idx) == passIdx))
                    {
                        if (!useYoung)
                        {
                            animalGroup = model.At(idx);
                        }
                        else
                        {
                            animalGroup = model.At(idx).Young;
                        }

                        GrazType.ZeroDMPool(ref pool);
                        if (animalGroup != null)
                        {
                            int n = (int)GrazType.TOMElement.n;
                            int p = (int)GrazType.TOMElement.p;
                            int s = (int)GrazType.TOMElement.s;

                            switch (propCode)
                            {
                            case StockProps.prpINTAKE:
                                pool.DM     = animalGroup.AnimalState.DM_Intake.Total;
                                pool.Nu[n]  = animalGroup.AnimalState.CP_Intake.Total / GrazType.N2Protein;
                                pool.Nu[p]  = animalGroup.AnimalState.Phos_Intake.Total;
                                pool.Nu[s]  = animalGroup.AnimalState.Sulf_Intake.Total;
                                pool.AshAlk = (animalGroup.AnimalState.PaddockIntake.AshAlkalinity * animalGroup.AnimalState.PaddockIntake.Biomass)
                                              + (animalGroup.AnimalState.SuppIntake.AshAlkalinity * animalGroup.AnimalState.SuppIntake.Biomass);
                                break;

                            case StockProps.prpINTAKE_PAST:
                                pool.DM     = animalGroup.AnimalState.DM_Intake.Herbage;
                                pool.Nu[n]  = animalGroup.AnimalState.CP_Intake.Herbage / GrazType.N2Protein;
                                pool.Nu[p]  = animalGroup.AnimalState.Phos_Intake.Herbage;
                                pool.Nu[s]  = animalGroup.AnimalState.Sulf_Intake.Herbage;
                                pool.AshAlk = animalGroup.AnimalState.PaddockIntake.AshAlkalinity * animalGroup.AnimalState.PaddockIntake.Biomass;
                                break;

                            case StockProps.prpINTAKE_SUPP:
                                pool.DM     = animalGroup.AnimalState.DM_Intake.Supp;
                                pool.Nu[n]  = animalGroup.AnimalState.CP_Intake.Supp / GrazType.N2Protein;
                                pool.Nu[p]  = animalGroup.AnimalState.Phos_Intake.Supp;
                                pool.Nu[s]  = animalGroup.AnimalState.Sulf_Intake.Supp;
                                pool.AshAlk = animalGroup.AnimalState.SuppIntake.AshAlkalinity * animalGroup.AnimalState.SuppIntake.Biomass;
                                break;

                            case StockProps.prpFAECES:
                                GrazType.AddDMPool(animalGroup.AnimalState.OrgFaeces, pool);
                                GrazType.AddDMPool(animalGroup.AnimalState.InOrgFaeces, pool);
                                break;

                            case StockProps.prpINORG_FAECES:
                                GrazType.AddDMPool(animalGroup.AnimalState.InOrgFaeces, pool);
                                break;

                            default:
                                result = false;
                                break;
                            }
                        }

                        if (!useTag && !useAll)
                        {
                            DMPool2Value(pool, ref poolValues[idx - 1], (propCode == StockProps.prpINORG_FAECES));
                        }
                        else if (animalGroup != null)
                        {
                            GrazType.AddDMPool(GrazType.MultiplyDMPool(pool, animalGroup.NoAnimals), totalPool);
                            denom = denom + animalGroup.NoAnimals;
                        }
                    }
                } // _ loop over animal groups _

                if (useTag || useAll)
                {
                    if (denom > 0)
                    {
                        totalPool = GrazType.PoolFraction(totalPool, 1.0 / denom);
                    }
                    if (useAll)
                    {
                        DMPool2Value(totalPool, ref poolValues[0], (propCode == StockProps.prpINORG_FAECES));
                    }
                    else
                    {
                        DMPool2Value(totalPool, ref poolValues[passIdx - 1], (propCode == StockProps.prpINORG_FAECES));
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populate the dry matter pool
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="iCode"></param>
        /// <param name="bUseYoung"></param>
        /// <param name="bUseAll"></param>
        /// <param name="bUseTag"></param>
        /// <param name="aValue"></param>
        /// <returns></returns>
        public static bool PopulateDMPoolValue(TStockList Model, int iCode, bool bUseYoung, bool bUseAll, bool bUseTag, ref TDMPoolHead[] aValue)
        {
            int          iNoPasses;
            TAnimalGroup aGroup;

            GrazType.DM_Pool Pool      = new GrazType.DM_Pool();
            GrazType.DM_Pool TotalPool = new GrazType.DM_Pool();
            int iDenom;
            int iPass, Idx;

            bool Result = true;

            for (int i = 0; i < aValue.Length; i++)
            {
                aValue[i] = new TDMPoolHead();
            }

            if (bUseTag)
            {
                iNoPasses = aValue.Length;
            }
            else
            {
                iNoPasses = 1;
            }

            for (iPass = 1; iPass <= iNoPasses; iPass++)
            {
                GrazType.ZeroDMPool(ref TotalPool);
                iDenom = 0;

                for (Idx = 1; Idx <= Model.Count(); Idx++)
                {
                    if (!bUseTag || (Model.getTag(Idx) == iPass))
                    {
                        if (!bUseYoung)
                        {
                            aGroup = Model.At(Idx);
                        }
                        else
                        {
                            aGroup = Model.At(Idx).Young;
                        }

                        GrazType.ZeroDMPool(ref Pool);
                        if (aGroup != null)
                        {
                            int N = (int)GrazType.TOMElement.N;
                            int P = (int)GrazType.TOMElement.P;
                            int S = (int)GrazType.TOMElement.S;

                            switch (iCode)
                            {
                            case StockProps.prpINTAKE:
                                Pool.DM     = aGroup.AnimalState.DM_Intake.Total;
                                Pool.Nu[N]  = aGroup.AnimalState.CP_Intake.Total / GrazType.N2Protein;
                                Pool.Nu[P]  = aGroup.AnimalState.Phos_Intake.Total;
                                Pool.Nu[S]  = aGroup.AnimalState.Sulf_Intake.Total;
                                Pool.AshAlk = aGroup.AnimalState.PaddockIntake.AshAlkalinity * aGroup.AnimalState.PaddockIntake.Biomass
                                              + aGroup.AnimalState.SuppIntake.AshAlkalinity * aGroup.AnimalState.SuppIntake.Biomass;
                                break;

                            case StockProps.prpINTAKE_PAST:
                                Pool.DM     = aGroup.AnimalState.DM_Intake.Herbage;
                                Pool.Nu[N]  = aGroup.AnimalState.CP_Intake.Herbage / GrazType.N2Protein;
                                Pool.Nu[P]  = aGroup.AnimalState.Phos_Intake.Herbage;
                                Pool.Nu[S]  = aGroup.AnimalState.Sulf_Intake.Herbage;
                                Pool.AshAlk = aGroup.AnimalState.PaddockIntake.AshAlkalinity * aGroup.AnimalState.PaddockIntake.Biomass;
                                break;

                            case StockProps.prpINTAKE_SUPP:
                                Pool.DM     = aGroup.AnimalState.DM_Intake.Supp;
                                Pool.Nu[N]  = aGroup.AnimalState.CP_Intake.Supp / GrazType.N2Protein;
                                Pool.Nu[P]  = aGroup.AnimalState.Phos_Intake.Supp;
                                Pool.Nu[S]  = aGroup.AnimalState.Sulf_Intake.Supp;
                                Pool.AshAlk = aGroup.AnimalState.SuppIntake.AshAlkalinity * aGroup.AnimalState.SuppIntake.Biomass;
                                break;

                            case StockProps.prpFAECES:
                                GrazType.AddDMPool(aGroup.AnimalState.OrgFaeces, Pool);
                                GrazType.AddDMPool(aGroup.AnimalState.InOrgFaeces, Pool);
                                break;

                            case StockProps.prpINORG_FAECES:
                                GrazType.AddDMPool(aGroup.AnimalState.InOrgFaeces, Pool);
                                break;

                            default:
                                Result = false;
                                break;
                            }
                        }

                        if (!bUseTag && !bUseAll)
                        {
                            DMPool2Value(Pool, aValue[Idx - 1], (iCode == StockProps.prpINORG_FAECES));
                        }
                        else if (aGroup != null)
                        {
                            GrazType.AddDMPool(GrazType.MultiplyDMPool(Pool, aGroup.NoAnimals), TotalPool);
                            iDenom = iDenom + aGroup.NoAnimals;
                        }
                    }
                } //_ loop over animal groups _

                if (bUseTag || bUseAll)
                {
                    if (iDenom > 0)
                    {
                        TotalPool = GrazType.PoolFraction(TotalPool, 1.0 / iDenom);
                    }
                    if (bUseAll)
                    {
                        DMPool2Value(TotalPool, aValue[0], (iCode == StockProps.prpINORG_FAECES));
                    }
                    else
                    {
                        DMPool2Value(TotalPool, aValue[iPass - 1], (iCode == StockProps.prpINORG_FAECES));
                    }
                }
            }
            return(Result);
        }