示例#1
0
        /// <summary>Constructor.</summary>
        /// <param name="soilThicknesses">Soil thicknesses (mm).</param>
        /// <param name="nutrientPatchManager">The nutrient patch manager.</param>
        public NutrientPatch(double[] soilThicknesses, NutrientPatchManager nutrientPatchManager)
        {
            soilThickness = soilThicknesses;
            patchManager  = nutrientPatchManager;
            var simulations = FileFormat.ReadFromString <Simulations>(ReflectionUtilities.GetResourceAsString("Models.Resources.Nutrient.json"), e => throw e, false);

            if (simulations.Children.Count != 1 || !(simulations.Children[0] is Nutrient))
            {
                throw new Exception("Cannot create nutrient model in NutrientPatchManager");
            }
            Nutrient          = simulations.Children[0] as Nutrient;
            Nutrient.IsHidden = true;

            // Find all solutes.
            foreach (ISolute solute in Nutrient.FindAllChildren <ISolute>())
            {
                solutes.Add(solute.Name, solute);
            }
            lignin = Nutrient.FindInScope <NutrientPool>("FOMLignin");
            if (lignin == null)
            {
                throw new Exception("Cannot find lignin pool in the nutrient model.");
            }
            cellulose = Nutrient.FindInScope <NutrientPool>("FOMCellulose");
            if (cellulose == null)
            {
                throw new Exception("Cannot find cellulose pool in the nutrient model.");
            }
            carbohydrate = Nutrient.FindInScope <NutrientPool>("FOMCarbohydrate");
            if (carbohydrate == null)
            {
                throw new Exception("Cannot find carbohydrate pool in the nutrient model.");
            }
        }
示例#2
0
        /// <summary>Copy constructor.</summary>
        public NutrientPatch(NutrientPatch from)
        {
            soilThickness = from.soilThickness;
            patchManager  = from.patchManager;
            Nutrient      = Apsim.Clone(from.Nutrient) as Nutrient;
            Structure.Add(Nutrient, from.Nutrient.Parent);

            // Find all solutes.
            foreach (ISolute solute in Nutrient.FindAllChildren <ISolute>())
            {
                solutes.Add(solute.Name, solute);
            }
            lignin       = from.lignin;
            cellulose    = from.cellulose;
            carbohydrate = from.carbohydrate;
        }
示例#3
0
 /// <summary>
 /// Invoked when model is first created.
 /// </summary>
 public override void OnCreated()
 {
     base.OnCreated();
     soil         = FindAncestor <Soil>();
     patchManager = FindAncestor <NutrientPatchManager>();
 }