コード例 #1
0
        //----------------------- Public methods -----------------------

        /// <summary>Initialise this root instance (and tissues).</summary>
        /// <param name="zone">The zone the roots belong to.</param>
        /// <param name="minimumLiveWt">Minimum live DM biomass for this organ (kg/ha).</param>
        public void Initialise(Zone zone, double minimumLiveWt)
        {
            // link to soil models parameters
            soil = zone.FindInScope <Soil>();
            if (soil == null)
            {
                throw new Exception($"Cannot find soil in zone {zone.Name}");
            }

            soilPhysical = soil.FindInScope <IPhysical>();
            if (soilPhysical == null)
            {
                throw new Exception($"Cannot find soil physical in soil {soil.Name}");
            }

            waterBalance = soil.FindInScope <ISoilWater>();
            if (waterBalance == null)
            {
                throw new Exception($"Cannot find a water balance model in soil {soil.Name}");
            }

            soilCropData = soil.FindDescendant <SoilCrop>(species.Name + "Soil");
            if (soilCropData == null)
            {
                throw new Exception($"Cannot find a soil crop parameterisation called {species.Name + "Soil"}");
            }

            nutrient = zone.FindInScope <INutrient>();
            if (nutrient == null)
            {
                throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}");
            }

            no3 = zone.FindInScope("NO3") as ISolute;
            if (no3 == null)
            {
                throw new Exception($"Cannot find NO3 solute in zone {zone.Name}");
            }

            nh4 = zone.FindInScope("NH4") as ISolute;
            if (nh4 == null)
            {
                throw new Exception($"Cannot find NH4 solute in zone {zone.Name}");
            }

            // initialise soil related variables
            zoneName             = soil.Parent.Name;
            nLayers              = soilPhysical.Thickness.Length;
            mySoilNH4Available   = new double[nLayers];
            mySoilNO3Available   = new double[nLayers];
            mySoilWaterAvailable = new double[nLayers];

            // save minimum DM and get target root distribution
            MinimumLiveDM      = minimumLiveWt;
            TargetDistribution = RootDistributionTarget();

            // initialise tissues
            Live.Initialise();
            Dead.Initialise();
        }
コード例 #2
0
ファイル: NutrientContextMemory.cs プロジェクト: rikp777/Fit
        public bool Create(INutrient nutrient)
        {
            if (_nutrients.SingleOrDefault(f => f.Name == nutrient.Name) != null)
            {
                return(false);
            }

            _nutrients.Add(Map(nutrient));

            return(true);
        }
コード例 #3
0
 /// <summary>Constructor.</summary>
 /// <param name="speciesNam">The name of the species this tissue belongs to.</param>
 /// <param name="nutrient">The nutrient model.</param>
 /// <param name="numLayers">The number of layers in the soil</param>
 public RootTissue(string speciesNam, INutrient nutrient, int numLayers)
 {
     speciesName          = speciesNam;
     nutrientModel        = nutrient;
     nLayers              = numLayers;
     DMLayer              = new double[nLayers];
     NamountLayer         = new double[nLayers];
     PamountLayer         = new double[nLayers];
     DMLayersTransferedIn = new double[nLayers];
     NLayersTransferedIn  = new double[nLayers];
 }
コード例 #4
0
ファイル: NutrientContextMemory.cs プロジェクト: rikp777/Fit
        private static NutrientDto Map(INutrient nutrient)
        {
            var nutrientDto = new NutrientDto
            {
                Id        = _nutrients.Max(u => u.Id) + 1,
                Name      = nutrient.Name,
                MaxIntake = nutrient.MaxIntake
            };

            return(nutrientDto);
        }
コード例 #5
0
        /// <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>
        public void Initialise(Zone zone, double initialDM, double initialDepth,
                               double minLiveDM)
        {
            soil = zone.FindInScope <Soil>();
            if (soil == null)
            {
                throw new Exception($"Cannot find soil in zone {zone.Name}");
            }

            nutrient = zone.FindInScope <INutrient>();
            if (nutrient == null)
            {
                throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}");
            }

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

            // save the parameters for this organ
            nLayers       = soil.Thickness.Length;
            minimumLiveDM = minLiveDM;
            dulMM         = soil.DULmm;
            ll15MM        = soil.LL15mm;
            Live          = tissue[0];
            Dead          = tissue[1];

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

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

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

            // Initialise the live tissue.
            Live.Initialise(initialDMByLayer, initialNByLayer);
            Dead.Initialise(null, null);
        }
コード例 #6
0
ファイル: NutrientLogic.cs プロジェクト: rikp777/Fit
        // <summary>
        ///
        ///     return true when valid
        ///
        ///     Exception      =
        ///                    = maxintake cant be more than 2000
        ///                    = Name cant be more than 50
        ///
        /// </summary>
        private bool validation(INutrient nutrient)
        {
            if (nutrient.MaxIntake > 2000)
            {
                return(false);
            }
            if (nutrient.Name.Length > 50)
            {
                return(false);
            }


            return(true);
        }
コード例 #7
0
        public bool Create(INutrient nutrient)
        {
            var parameters = new Dictionary <string, object>
            {
                { "Name", nutrient.Name },
                { "MaxIntake", nutrient.MaxIntake }
            };

            var success = HelpFunctions.nonQuery("Nutrient_Insert", parameters);

            InstantiateContextSQL();

            return(success);
        }
コード例 #8
0
ファイル: Soil.cs プロジェクト: Ysovuka/farming-system
        public void Absorb(INutrient nutrient)
        {
            INutrient nourishment = Nutrients.FirstOrDefault(n => n.Name.Equals(nutrient.Name));

            if (nourishment != null)
            {
                Nutrients.Remove(nourishment);
                nourishment.Absorb(nutrient.Level);

                Nutrients.Add(nourishment);
            }
            else
            {
                Nutrients.Add(nutrient);
            }
        }
コード例 #9
0
ファイル: NutrientLogic.cs プロジェクト: rikp777/Fit
        /// <summary>
        ///
        ///     Create
        ///
        ///     Right    = Admin, Instructor
        ///
        ///     Exception     = validation
        ///
        /// </summary>
        public bool Edit(int userId, INutrient nutrient)
        {
            if (!UserLogic.CheckRight(userId, Right.Admin) || UserLogic.CheckRight(userId, Right.Instructor))
            {
                return(false);
            }


            if (!validation(nutrient))
            {
                return(false);
            }


            return(_nutrientRepository.Edit(nutrient));
        }
コード例 #10
0
ファイル: NutrientContextMemory.cs プロジェクト: rikp777/Fit
 public bool Update(INutrient nutrient)
 {
     if (_nutrients.SingleOrDefault(n => n.Name == nutrient.Name) != null)
     {
         return(false);
     }
     try
     {
         _nutrients[nutrient.Id - 1] = Map(nutrient);
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     return(false);
 }
コード例 #11
0
ファイル: NutrientLogic.cs プロジェクト: rikp777/Fit
        /// <summary>
        ///
        ///     Create
        ///
        ///     Right    = Admin, Instructor
        ///
        ///     Exception     = validation
        ///
        /// </summary>
        public bool Add(int userId, INutrient nutrient)
        {
            if (!UserLogic.CheckRight(userId, Right.Admin) || UserLogic.CheckRight(userId, Right.Instructor))
            {
                return(false);
            }


            if (_nutrientRepository.GetBy(nutrient.Name) != null)
            {
                return(false);
            }
            if (!validation(nutrient))
            {
                return(false);
            }


            return(_nutrientRepository.Add(nutrient));
        }
コード例 #12
0
        /// <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>
        public void Initialise(Zone zone, double initialDM, double initialDepth,
                               double minLiveDM)
        {
            soil = zone.FindInScope <Soil>();
            if (soil == null)
            {
                throw new Exception($"Cannot find soil in zone {zone.Name}");
            }

            soilPhysical = soil.FindInScope <IPhysical>();
            if (soilPhysical == null)
            {
                throw new Exception($"Cannot find soil physical in soil {soil.Name}");
            }

            waterBalance = soil.FindInScope <ISoilWater>();
            if (waterBalance == null)
            {
                throw new Exception($"Cannot find a water balance model in soil {soil.Name}");
            }

            soilCropData = soil.FindDescendant <SoilCrop>(species.Name + "Soil");
            if (soilCropData == null)
            {
                throw new Exception($"Cannot find a soil crop parameterisation called {species.Name + "Soil"}");
            }

            nutrient = zone.FindInScope <INutrient>();
            if (nutrient == null)
            {
                throw new Exception($"Cannot find SoilNitrogen in zone {zone.Name}");
            }

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

            // link to soil and initialise related variables
            zoneName           = soil.Parent.Name;
            nLayers            = soilPhysical.Thickness.Length;
            dulMM              = soilPhysical.DULmm;
            ll15MM             = soilPhysical.LL15mm;
            mySoilNH4Available = new double[nLayers];
            mySoilNO3Available = new double[nLayers];

            // save minimum DM and get target root distribution
            Depth         = initialDepth;
            minimumLiveDM = minLiveDM;
            CalculateRootZoneBottomLayer();
            TargetDistribution = RootDistributionTarget();

            // initialise tissues
            double[] initialDMByLayer = MathUtilities.Multiply_Value(CurrentRootDistributionTarget(), initialDM);
            double[] initialNByLayer  = MathUtilities.Multiply_Value(initialDMByLayer, NConcOptimum);
            Live = tissue[0];
            Dead = tissue[1];
            Live.Initialise(initialDMByLayer, initialNByLayer);
            Dead.Initialise(null, null);
        }
コード例 #13
0
ファイル: NutrientContextMemory.cs プロジェクト: rikp777/Fit
 public INutrient Read(INutrient nutrient)
 {
     return(_nutrients.SingleOrDefault(n => n.Id == nutrient.Id));
 }
コード例 #14
0
ファイル: Soil.cs プロジェクト: Ysovuka/farming-system
 public float Nourishment(INutrient nutrient)
 {
     return(Nutrients.FirstOrDefault(n => n.Name.Equals(nutrient.Name))?.Level
            ?? 0);
 }
コード例 #15
0
        /// <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];
            }
        }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
 public bool Edit(INutrient nutrient) => _context.Update(nutrient);
コード例 #18
0
 public bool Add(INutrient nutrient) => _context.Create(nutrient);
コード例 #19
0
 public INutrient GetBy(INutrient nutrient) => _context.Read(nutrient);
コード例 #20
0
        public INutrient Read(INutrient nutrient)
        {
            var nutrientDto = Read(nutrient.Id);

            return(nutrientDto);
        }
コード例 #21
0
ファイル: NutrientLogic.cs プロジェクト: rikp777/Fit
 public INutrient GetBy(INutrient nutrient) => _nutrientRepository.GetBy(nutrient);