/// <summary>Constructor, initialise tissues for the roots.</summary>
        /// <param name="nameOfSpecies">Name of the pasture species</param>
        /// <param name="numTissues">Number of tissues in this organ</param>
        /// <param name="initialDM">Initial dry matter weight</param>
        /// <param name="initialDepth">Initial root depth</param>
        /// <param name="optNconc">The optimum N concentration</param>
        /// <param name="minNconc">The minimum N concentration</param>
        /// <param name="maxNconc">The maximum N concentration</param>
        /// <param name="minLiveDM">The minimum biomass for this organ</param>
        /// <param name="specificRootLength">The specific root length (m/g)</param>
        /// <param name="rootDepthMaximum">The maximum root depth</param>
        /// <param name="rootDistributionDepthParam">Parameter to compute root distribution, depth with constant root</param>
        /// <param name="rootBottomDistributionFactor">Parameter to compute root distribution, </param>
        /// <param name="rootDistributionExponent">Parameter to compute root distribution, exponent for root decrease</param>
        /// <param name="waterAvailableMethod">Method to compute water available</param>
        /// <param name="nitrogenAvailableMethod">Method to compute N available</param>
        /// <param name="kNH4">Parameter to compute NN4 available, default method</param>
        /// <param name="kNO3">Parameter to compute NO3 available, default method</param>
        /// <param name="maxNUptake">Parameter to compute N uptake, default method</param>
        /// <param name="kuNH4">Parameter to compute NH4 available, alternative method</param>
        /// <param name="kuNO3">Parameter to compute NO3 available, alternative method</param>
        /// <param name="referenceKSuptake">Parameter to compute available water, conductivity</param>
        /// <param name="referenceRLD">Parameter to compute available water, roots</param>
        /// <param name="exponentSoilMoisture">Parameter to compute available water</param>
        /// <param name="theSoil">Reference to the soil in the zone these roots are in</param>
        public PastureBelowGroundOrgan(string nameOfSpecies, int numTissues,
                                       double initialDM, double initialDepth,
                                       double optNconc, double minNconc, double maxNconc,
                                       double minLiveDM,
                                       double specificRootLength, double rootDepthMaximum,
                                       double rootDistributionDepthParam, double rootDistributionExponent,
                                       double rootBottomDistributionFactor,
                                       PastureSpecies.PlantAvailableWaterMethod waterAvailableMethod,
                                       PastureSpecies.PlantAvailableNitrogenMethod nitrogenAvailableMethod,
                                       double kNH4, double kNO3, double maxNUptake,
                                       double kuNH4, double kuNO3, double referenceKSuptake,
                                       double referenceRLD, double exponentSoilMoisture,
                                       Soil theSoil)
        {
            mySoil       = theSoil;
            SoilNitrogen = Apsim.Find(mySoil, typeof(INutrient)) as INutrient;
            if (SoilNitrogen == null)
            {
                throw new Exception("Cannot find SoilNitrogen in zone");
            }

            // Typically two tissues below ground, one live and one dead
            Tissue  = new RootTissue[numTissues];
            nLayers = theSoil.Thickness.Length;
            for (int t = 0; t < Tissue.Length; t++)
            {
                Tissue[t] = new RootTissue(nameOfSpecies, SoilNitrogen, nLayers);
            }

            // save the parameters for this organ
            mySpeciesName                  = nameOfSpecies;
            NConcOptimum                   = optNconc;
            NConcMinimum                   = minNconc;
            NConcMaximum                   = maxNconc;
            MinimumLiveDM                  = minLiveDM;
            mySpecificRootLength           = specificRootLength;
            myRootDepthMaximum             = rootDepthMaximum;
            myRootDistributionDepthParam   = rootDistributionDepthParam;
            myRootDistributionExponent     = rootDistributionExponent;
            myRootBottomDistributionFactor = rootBottomDistributionFactor;
            myWaterAvailableMethod         = waterAvailableMethod;
            myNitrogenAvailableMethod      = nitrogenAvailableMethod;
            myKNO3                 = kNO3;
            myKNH4                 = kNH4;
            myMaximumNUptake       = maxNUptake;
            myKuNH4                = kuNH4;
            myKuNO3                = kuNO3;
            myReferenceKSuptake    = referenceKSuptake;
            myReferenceRLD         = referenceRLD;
            myExponentSoilMoisture = exponentSoilMoisture;

            // Link to soil and initialise variables
            myZoneName         = mySoil.Parent.Name;
            mySoilNH4Available = new double[nLayers];
            mySoilNO3Available = new double[nLayers];
            NO3 = Apsim.Find(mySoil, "NO3") as ISolute;
            NH4 = Apsim.Find(mySoil, "NH4") as ISolute;

            // Initialise root DM, N, depth, and distribution
            Depth = initialDepth;
            TargetDistribution = RootDistributionTarget();
            double[] iniRootFraction = CurrentRootDistributionTarget();
            for (int layer = 0; layer < nLayers; layer++)
            {
                Tissue[0].DMLayer[layer]      = initialDM * iniRootFraction[layer];
                Tissue[0].NamountLayer[layer] = NConcOptimum * Tissue[0].DMLayer[layer];
            }
        }
        /// <summary>Constructor, initialise tissues for the roots.</summary>
        /// <param name="zone">The zone the roots belong in.</param>
        /// <param name="initialDM">Initial dry matter weight</param>
        /// <param name="initialDepth">Initial root depth</param>
        /// <param name="minLiveDM">The minimum biomass for this organ</param>
        /// <param name="waterAvailableMethod">Method to compute water available</param>
        /// <param name="nitrogenAvailableMethod">Method to compute N available</param>
        /// <param name="kNH4">Parameter to compute NN4 available, default method</param>
        /// <param name="kNO3">Parameter to compute NO3 available, default method</param>
        /// <param name="maxNUptake">Parameter to compute N uptake, default method</param>
        /// <param name="kuNH4">Parameter to compute NH4 available, alternative method</param>
        /// <param name="kuNO3">Parameter to compute NO3 available, alternative method</param>
        /// <param name="referenceKSuptake">Parameter to compute available water, conductivity</param>
        /// <param name="referenceRLD">Parameter to compute available water, roots</param>
        /// <param name="exponentSoilMoisture">Parameter to compute available water</param>
        public void Initialise(Zone zone, double initialDM, double initialDepth,
                               double minLiveDM,
                               PastureSpecies.PlantAvailableWaterMethod waterAvailableMethod,
                               PastureSpecies.PlantAvailableNitrogenMethod nitrogenAvailableMethod,
                               double kNH4, double kNO3, double maxNUptake,
                               double kuNH4, double kuNO3, double referenceKSuptake,
                               double referenceRLD, double exponentSoilMoisture)
        {
            mySoil = Apsim.Find(zone, typeof(Soil)) as Soil;
            if (mySoil == null)
            {
                throw new Exception($"Cannot find soil in zone {zone.Name}");
            }

            SoilNitrogen = Apsim.Find(zone, typeof(INutrient)) as INutrient;
            if (SoilNitrogen == null)
            {
                throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}");
            }

            NO3 = Apsim.Find(zone, "NO3") as ISolute;
            if (NO3 == null)
            {
                throw new Exception($"Cannot find NO3 solute in zone {zone.Name}");
            }
            NH4 = Apsim.Find(zone, "NH4") as ISolute;
            if (NH4 == null)
            {
                throw new Exception($"Cannot find NH4 solute in zone {zone.Name}");
            }

            // save the parameters for this organ
            nLayers                   = mySoil.Thickness.Length;
            MinimumLiveDM             = minLiveDM;
            myWaterAvailableMethod    = waterAvailableMethod;
            myNitrogenAvailableMethod = nitrogenAvailableMethod;
            myKNO3                 = kNO3;
            myKNH4                 = kNH4;
            myMaximumNUptake       = maxNUptake;
            myKuNH4                = kuNH4;
            myKuNO3                = kuNO3;
            myReferenceKSuptake    = referenceKSuptake;
            myReferenceRLD         = referenceRLD;
            myExponentSoilMoisture = exponentSoilMoisture;

            // Link to soil and initialise variables
            myZoneName         = mySoil.Parent.Name;
            mySoilNH4Available = new double[nLayers];
            mySoilNO3Available = new double[nLayers];

            // Initialise root DM, N, depth, and distribution
            Depth = initialDepth;
            TargetDistribution = RootDistributionTarget();

            double[] initialDMByLayer = MathUtilities.Multiply_Value(CurrentRootDistributionTarget(), initialDM);
            double[] initialNByLayer  = MathUtilities.Multiply_Value(initialDMByLayer, NConcOptimum);

            // Initialise the live tissue.
            Tissue[0].Initialise(initialDMByLayer, initialNByLayer);
            Tissue[1].Initialise(null, null);
        }