예제 #1
0
 /// <summary>
 /// Convert the dry matter pool
 /// </summary>
 /// <param name="pool">The DM pool</param>
 /// <param name="poolValue">The pool data</param>
 /// <param name="onlyNPSVal">The NPS values only</param>
 public static void DMPool2Value(GrazType.DM_Pool pool, ref DMPoolHead poolValue, bool onlyNPSVal = false)
 {
     if (!onlyNPSVal)
     {
         poolValue.Weight = pool.DM;                                         // Item[1] = "weight"   kg/head
         poolValue.N      = pool.Nu[(int)GrazType.TOMElement.n];             // Item[2] = "n"        kg/head
         poolValue.P      = pool.Nu[(int)GrazType.TOMElement.p];             // Item[3] = "p"        kg/head
         poolValue.S      = pool.Nu[(int)GrazType.TOMElement.s];             // Item[4] = "s"        kg/head
         poolValue.AshAlk = pool.AshAlk;                                     // Item[5] = "ash_alk"  mol/head
     }
     else
     {
         poolValue.N = pool.Nu[(int)GrazType.TOMElement.n];                   // Item[1] = "n"        kg/head
         poolValue.P = pool.Nu[(int)GrazType.TOMElement.p];                   // Item[2] = "p"        kg/head
         poolValue.S = pool.Nu[(int)GrazType.TOMElement.s];                   // Item[3] = "s"        kg/head
     }
 }
예제 #2
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);
        }