Example #1
0
        /// <summary>Partitions the dm.</summary>
        /// <param name="Organs">The organs.</param>
        /// <exception cref="System.Exception">Unknown Partition Rule  + PartitionRules[i]</exception>
        internal void PartitionDM(List <Organ1> Organs)
        {
            // Get all DM supply terms.
            DMSupply = 0;
            foreach (Organ1 Organ in Organs)
            {
                DMSupply += Organ.DMSupply;
            }

            // Tell each organ to do it's DM Demand
            foreach (Organ1 Organ in Organs)
            {
                Organ.DoDMDemand(DMSupply);
            }

            foreach (Organ1 Organ in Organs)
            {
                Organ.Growth.Clear();
            }

            double dm_remaining     = DMSupply;
            double dlt_dm_green_tot = 0.0;

            for (int i = 0; i != PartitionOrgans.Length; i++)
            {
                Organ1 Organ = FindOrgan(PartitionOrgans[i], Organs);

                if (PartitionRules[i] == "magic")
                {
                    Organ.GiveDmGreen(RatioRootShoot.Value * DMSupply);
                }
                else if (PartitionRules[i] == "seasonal")                  // (PFR)
                {
                    double uptake = RatioRootPlant * dm_remaining;
                    Organ.GiveDmGreen(uptake);                               // (PFR)
                    dm_remaining     = dm_remaining - uptake;                // Here total RUE is used so remaining discounts root uptake(PFR)
                    dlt_dm_green_tot = dlt_dm_green_tot + uptake;
                }

                else
                {
                    double uptake;
                    if (PartitionRules[i] == "demand")
                    {
                        uptake = Math.Min(Organ.DMGreenDemand, dm_remaining);
                    }
                    else if (PartitionRules[i] == "frac")
                    {
                        uptake = Math.Min(FracDMRemainingInPart(Organ.Name) * dm_remaining, Organ.DMGreenDemand);
                    }
                    else if (PartitionRules[i] == "remainder")
                    {
                        uptake = dm_remaining;
                    }
                    else
                    {
                        throw new Exception("Unknown Partition Rule " + PartitionRules[i]);
                    }

                    Organ.GiveDmGreen(uptake);
                    dm_remaining     = dm_remaining - uptake;
                    dlt_dm_green_tot = dlt_dm_green_tot + uptake;
                }
            }


            if (!MathUtilities.FloatsAreEqual(dlt_dm_green_tot, DMSupply, 1.0E-4f))
            {
                string msg = "dlt_dm_green_tot mass balance is off: "
                             + dlt_dm_green_tot.ToString("f6")
                             + " vs "
                             + DMSupply.ToString("f6");
                Summary.WriteWarning(this, msg);
            }

            Util.Debug("Arbitrator.DMSupply=%f", DMSupply);
            Util.Debug("Arbitrator.dlt_dm_green_tot=%f", dlt_dm_green_tot);
        }