Exemple #1
0
    void BucketCommand()
    {
        Soil soil = gameObject.transform.Find("plant").gameObject.GetComponent <Soil>();

        if (PlayerNecessity.Instance.Water != 0 && soil.isDilig())
        {
            Debug.Log("DILIG!");
            soil.Dilig();
            PlayerNecessity.Instance.ConsumeWater();
        }
        else
        {
            Debug.Log("NOT DILIG!");
            // DONT HAVE ENOUGH WATER
        }
    }
Exemple #2
0
 /// <summary>Initialises this instance.</summary>
 public void Initialise()
 {
     foreach (Zone Z in Apsim.ChildrenRecursively(this.Parent, typeof(Zone)))
     {
         Soil soil = Apsim.Child(Z, typeof(Soil)) as Soil;
         if (soil != null)
         {
             ZoneWaterAndN NewZ = new ZoneWaterAndN();
             NewZ.Name  = Z.Name;
             NewZ.Water = soil.Water;
             NewZ.NO3N  = soil.NO3N;
             NewZ.NH4N  = soil.NH4N;
             Zones.Add(NewZ);
         }
     }
 }
Exemple #3
0
        public void ImproveNutrientInSoil()
        {
            ISoil     soil     = new Soil();
            INutrient nitrogen = new Nutrient("Nitrogen");

            soil.Absorb(nitrogen);

            Assert.True(soil.Nourishment(nitrogen) > 0);

            soil.Sterilize();
            INutrient phosphorus = new Nutrient("Phosphorus");

            soil.Absorb(phosphorus);

            Assert.True(soil.Nourishment(nitrogen) == 0);
        }
Exemple #4
0
        public static void WaterContainedPlant(IGameObject obj)
        {
            if (!(obj is ISoilRug) && !(obj is IPlanterBowl))
            {
                return;
            }

            foreach (Slot slot in obj.GetContainmentSlots())
            {
                Soil soil = obj.GetContainedObject(slot) as Soil;
                if (soil != null)
                {
                    soil.OnSprinkled();
                }
            }
        }
Exemple #5
0
        public void PullEverything_PotWithFlower_ReturnsCurrentContent()
        {
            // arrange
            var pot    = new Pot();
            var flower = new Flower(new PlantSource(Plants.Hedera, SeedType.Seedling));
            var soil   = new Soil("");

            new Planting(flower, soil, pot);

            // act
            var result = pot.PullEverything();

            // assert
            Assert.AreEqual(flower, result.Item2);
            Assert.AreEqual(soil, result.Item1.Item);
        }
Exemple #6
0
 public void NO3UnitsSet(NUnitsEnum ToUnits, Soil Soil)
 {
     if (ToUnits != NO3Units)
     {
         // convert the numbers
         if (ToUnits == NUnitsEnum.ppm)
         {
             NO3 = NO3ppm(Soil);
         }
         else
         {
             NO3 = NO3kgha(Soil);
         }
         NO3Units = ToUnits;
     }
 }
Exemple #7
0
 public void CheckSoil(object sender, EventArgs e)
 {
     try
     {
         Soil currentSoil = this.explorerPresenter.ApsimXFile.FindByPath(this.explorerPresenter.CurrentNodePath)?.Value as Soil;
         if (currentSoil != null)
         {
             SoilChecker.CheckWithStandardisation(currentSoil);
             explorerPresenter.MainPresenter.ShowMessage("Soil water parameters are valid.", Simulation.MessageType.Information);
         }
     }
     catch (Exception err)
     {
         explorerPresenter.MainPresenter.ShowError(err);
     }
 }
Exemple #8
0
        public void SetPart_AfterEndEditing_ReduceProportions()
        {
            // arrange
            var soil = new Soil()
            {
                Soil.Part <Sand>(5), Soil.Part <Turf>(1)
            };

            // act
            soil.EndEdit();
            soil.Set <Turf>(5);

            // assert
            Assert.AreEqual(1, soil.PartsOf <Sand>());
            Assert.AreEqual(1, soil.PartsOf <Turf>());
        }
Exemple #9
0
        public void SetPart_WithPositiveCount_SetParts()
        {
            // arrange
            var soil = new Soil()
            {
                Soil.Part <Sand>(1), Soil.Part <Turf>(1)
            };

            // act
            soil.Set <Sand>(2);
            soil.Set <Turf>(1);

            // assert
            Assert.AreEqual(2, soil.PartsOf <Sand>());
            Assert.AreEqual(1, soil.PartsOf <Turf>());
        }
Exemple #10
0
 public Soil getSoil(String name)
 {
     //soil not in DB
     if (!soilData.ContainsKey(name))
     {
         return(null);
     }
     //soil instance already created
     if (soils.ContainsKey(name))
     {
         return(soils[name]);
     }
     //create new instance
     soils[name] = new Soil(name, this);
     return(soils[name]);
 }
Exemple #11
0
 public SoilViewModel(Soil soil)
 {
     this.SoilId      = soil.SoilId;
     this.Name        = soil.Name;
     this.ShortName   = soil.ShortName;
     this.Description = soil.Description;
     this.DepthLimit  = soil.DepthLimit;
     this.FarmId      = soil.FarmId;
     this.Farm        = soil.Farm;
     this.PositionId  = soil.PositionId;
     this.TestDate    = soil.TestDate;
     this.Latitude    = soil.Position.Latitude;
     this.Longitude   = soil.Position.Longitude;
     this.Position    = soil.Position;
     this.Horizonts   = soil.HorizonList;
 }
Exemple #12
0
        /// <summary>
        /// Called whenever the control is loaded and made visible.
        /// </summary>
        protected override void OnLoad()
        {
            // We need not just the XML for this profile node but the whole soil XML.
            Component SoilComponent = Controller.ApsimData.Find(NodePath).Parent;

            if (SoilComponent.Type.ToLower() != "soil")
            {
                SoilComponent = SoilComponent.Parent;
            }
            Soil = Soil.Create(SoilComponent.FullXMLNoShortCuts());
            Properties.OnLoad(Controller, NodePath, Data.OuterXml);
            Properties.OnLoad(Soil);

            // Get a component that represents the node we're to
            OurComponent = Controller.ApsimData.Find(NodePath);
            if (OurComponent.ShortCutTo != null)
            {
                OurComponent = OurComponent.ShortCutTo;
            }

            // Call OnLoad in our graph
            Graph         = new SoilGraphUI();
            Graph.Parent  = this;
            Graph.Visible = true;
            Graph.Dock    = DockStyle.Fill;
            Graph.BringToFront();

            // Load in the splitter position.
            string SplitterPositionString = Configuration.Instance.Setting("SoilSplitterPosition");

            if (SplitterPositionString != "")
            {
                TopPanel.Height = Convert.ToInt32(SplitterPositionString);
            }

            // add some extra items to the context menu.
            if (Grid.ContextMenuStrip != null && Grid.ContextMenuStrip.Items.Count != 8 &&
                (OurComponent.Type == "Water" || OurComponent.Type == "Analysis"))
            {
                Grid.ContextMenuStrip.Items.Add(new ToolStripSeparator());

                ToolStripMenuItem Item = (ToolStripMenuItem)Grid.ContextMenuStrip.Items.Add("Edit Metadata...");
                Item.ShortcutKeys = Keys.Control | Keys.M;
                Item.Click       += new System.EventHandler(OnMetadataClick);
            }
            panel1.Visible = OurComponent.Type == "Water";
        }
Exemple #13
0
        /// <summary>
        /// Growth depth of roots in this zone
        /// </summary>
        public void GrowRootDepth()
        {
            // Do Root Front Advance
            int RootLayer         = SoilUtilities.LayerIndexOfDepth(Physical.Thickness, Depth);
            var rootfrontvelocity = rootFrontVelocity.Value(RootLayer);

            double MaxDepth;

            double[] xf = null;
            if (!IsWeirdoPresent)
            {
                var soilCrop = Soil.FindDescendant <SoilCrop>(plant.Name + "Soil");
                if (soilCrop == null)
                {
                    throw new Exception($"Cannot find a soil crop parameterisation called {plant.Name}Soil");
                }

                xf = soilCrop.XF;

                Depth    = Depth + rootfrontvelocity * xf[RootLayer];
                MaxDepth = 0;
                // Limit root depth for impeded layers
                for (int i = 0; i < Physical.Thickness.Length; i++)
                {
                    if (xf[i] > 0)
                    {
                        MaxDepth += Physical.Thickness[i];
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                Depth    = Depth + rootfrontvelocity;
                MaxDepth = Physical.Thickness.Sum();
            }

            // Limit root depth for the crop specific maximum depth
            MaxDepth = Math.Min(maximumRootDepth.Value(), MaxDepth);
            Depth    = Math.Min(Depth, MaxDepth);

            RootFront = Depth;
            root.RootShape.CalcRootProportionInLayers(this);
        }
Exemple #14
0
        public Planting(Flower flower, Soil soil, Pot pot)
        {
            // садить только цветок без горшка в пустой горшок
            Contract.Requires <ArgumentException>(flower.GetPot(DateTime.UtcNow) == null);
            Contract.Requires <ArgumentException>(pot.GetFlower(DateTime.UtcNow) == null);

            Contract.Ensures(pot.GetFlower(this.Date) == flower, "must be planted flower in pot on date of planting");
            Contract.Ensures(flower.GetPot(this.Date) == pot, "flower must be in this pot on date of planting");

            this.pot    = pot;
            this.soil   = soil;
            this.flower = flower;

            pot.Events.Add(this);
            flower.Events.Add(this);
            Debug.WriteLine("{0} planted to {1} with {2}", flower, pot, soil);
        }
Exemple #15
0
 /// <summary>Sets the sample thickness.</summary>
 /// <param name="swim">The swim model.</param>
 /// <param name="thickness">The thickness to change the sample to.</param>
 /// <param name="soil">The soil</param>
 private static void SetSWIMThickness(Swim3 swim, double[] thickness, Soil soil)
 {
     foreach (var soluteParameters in soil.FindAllChildren <SwimSoluteParameters>())
     {
         if (!MathUtilities.AreEqual(thickness, soluteParameters.Thickness))
         {
             if (soluteParameters.Exco != null)
             {
                 soluteParameters.Exco = MapConcentration(soluteParameters.Exco, soluteParameters.Thickness, thickness, 0.2);
             }
             if (soluteParameters.FIP != null)
             {
                 soluteParameters.FIP = MapConcentration(soluteParameters.FIP, soluteParameters.Thickness, thickness, 0.2);
             }
         }
     }
 }
		public override void Cleanup()
		{
			if (mObjectsToPlant != null)
			{
				while (mObjectsToPlant.Count > 0)
				{
					CleanupPlantInstances(mObjectsToPlant[0], Actor, PlantInteractionType);
					mObjectsToPlant.RemoveAt(0);
				}
			}
			if (mDummyIk != null)
			{
				mDummyIk.Destroy();
				mDummyIk = null;
			}
			base.Cleanup();
		}
Exemple #17
0
        public void CheckSoil(object sender, EventArgs e)
        {
            Soil currentSoil = Apsim.Get(this.explorerPresenter.ApsimXFile, this.explorerPresenter.CurrentNodePath) as Soil;

            if (currentSoil != null)
            {
                string errorMessages = currentSoil.Check(false);
                if (!string.IsNullOrEmpty(errorMessages))
                {
                    explorerPresenter.MainPresenter.ShowError(errorMessages);
                }
                else
                {
                    explorerPresenter.MainPresenter.ShowMessage("Soil water parameters are valid.", Simulation.MessageType.Information);
                }
            }
        }
Exemple #18
0
        public void AddPart_AfterBeginEditing_ChangesProportions()
        {
            // arrange
            var soil = new Soil()
            {
                Soil.Part <Sand>(1), Soil.Part <Turf>(3)
            };

            // act
            soil.EndEdit();
            soil.BeginEdit();
            soil.Add <Sand>(2);

            // assert
            Assert.AreEqual(3, soil[SoilParts.Sand]);
            Assert.AreEqual(3, soil[SoilParts.Turf]);
        }
Exemple #19
0
        private new void OnSimulationCommencing(object sender, EventArgs e)
        {
            Soil soil = Apsim.Find(this, typeof(Soil)) as Soil;

            if (soil == null)
            {
                throw new Exception("Cannot find soil");
            }
            if (soil.Crop(Plant.Name) == null && soil.Weirdo == null)
            {
                throw new Exception("Cannot find a soil crop parameterisation for " + Plant.Name);
            }

            PlantZone = new ZoneState(Plant, this, soil, 0, InitialDM.Value(), Plant.Population, MaximumNConc.Value());
            Zones     = new List <ZoneState>();
            base.OnSimulationCommencing(sender, e);
        }
Exemple #20
0
        /// <summary>
        /// Update the Soil from Farm Soil List,
        /// If do not exists return null
        /// </summary>
        /// <param name="pName"></param>
        /// <param name="pShortName"></param>
        /// <param name="pDescription"></param>
        /// <param name="pLocation"></param>
        /// <param name="pTestDate"></param>
        /// <param name="pDepthLimit"></param>
        /// <param name="pFarmId"></param>
        /// <returns></returns>
        public Soil UpdateSoil(String pName, String pShortName, String pDescription, long pPositionId,
                               DateTime pTestDate, double pDepthLimit, long pFarmId)
        {
            Soil lReturn = null;
            Soil lSoil   = new Soil(this.GetNewSoilListId(), pName, pShortName, pDescription, pPositionId, pTestDate, pDepthLimit, pFarmId);

            lReturn = ExistSoil(lSoil);
            if (lReturn != null)
            {
                lReturn.Name        = pName;
                lReturn.Description = pDescription;
                lReturn.PositionId  = pPositionId;
                lReturn.TestDate    = pTestDate;
                lReturn.DepthLimit  = pDepthLimit;
            }
            return(lReturn);
        }
Exemple #21
0
 /// <summary>
 /// Set the crop values in the table for the specified crop name.
 /// </summary>
 private static void SetCropValues(DataTable Table, string CropName, Soil Soil, int StartRow)
 {
     if (Soil.CropNames.Contains(CropName, StringComparer.CurrentCultureIgnoreCase))
     {
         SetDoubleValues(Table, CropName + " ll (mm/mm)", Soil.Crop(CropName).LL, StartRow);
         SetCodeValues(Table, CropName + " llCode", Soil.Crop(CropName).LLMetadata, StartRow);
         SetDoubleValues(Table, CropName + " kl (/day)", Soil.Crop(CropName).KL, StartRow);
         SetDoubleValues(Table, CropName + " xf (0-1)", Soil.Crop(CropName).XF, StartRow);
     }
     else if (!Table.Columns.Contains(CropName + " ll (mm/mm)"))
     {
         Table.Columns.Add(CropName + " ll (mm/mm)", typeof(double));
         Table.Columns.Add(CropName + " llCode", typeof(string));
         Table.Columns.Add(CropName + " kl (/day)", typeof(double));
         Table.Columns.Add(CropName + " xf (0-1)", typeof(double));
     }
 }
Exemple #22
0
        /// <summary>Fills in missing values where possible.</summary>
        /// <param name="soil">The soil.</param>
        public static void FillInMissingValues(Soil soil)
        {
            AddPredictedCrops(soil);
            CheckAnalysisForMissingValues(soil);

            var water = soil.FindChild <Physical>();

            if (water != null)
            {
                var crops = water.FindAllChildren <SoilCrop>().Cast <SoilCrop>().ToArray();

                foreach (var crop in crops)
                {
                    if (crop.XF == null)
                    {
                        crop.XF         = MathUtilities.CreateArrayOfValues(1.0, water.Thickness.Length);
                        crop.XFMetadata = StringUtilities.CreateStringArray("Estimated", water.Thickness.Length);
                    }
                    if (crop.KL == null)
                    {
                        FillInKLForCrop(crop);
                    }

                    CheckCropForMissingValues(crop, soil);

                    // Modify wheat crop for sub soil constraints.
                    if (crop.Name.Equals("wheat", StringComparison.InvariantCultureIgnoreCase))
                    {
                        ModifyKLForSubSoilConstraints(crop, soil);
                    }
                }
            }

            var samples = soil.FindAllChildren <Sample>().Cast <Sample>().ToArray();

            foreach (Sample sample in samples)
            {
                CheckSampleForMissingValues(sample, soil);
            }

            // Make sure there are the correct number of KS values.
            if (water?.KS != null && water?.KS.Length > 0)
            {
                water.KS = FillMissingValues(water.KS, water.Thickness.Length, 0.0);
            }
        }
Exemple #23
0
        /// <summary>Sets the sample thickness.</summary>
        /// <param name="sample">The sample.</param>
        /// <param name="thickness">The thickness to change the sample to.</param>
        /// <param name="soil">The soil</param>
        private static void SetSampleThickness(Sample sample, double[] thickness, Soil soil)
        {
            if (!MathUtilities.AreEqual(thickness, sample.Thickness))
            {
                if (sample.SW != null)
                {
                    sample.SW = MapSW(sample.SW, sample.Thickness, thickness, soil);
                }
                if (sample.NH4 != null)
                {
                    sample.NH4      = MapConcentration(sample.NH4ppm, sample.Thickness, thickness, 0.2);
                    sample.NH4Units = Sample.NUnitsEnum.ppm;
                }
                if (sample.NO3 != null)
                {
                    sample.NO3      = MapConcentration(sample.NO3ppm, sample.Thickness, thickness, 1.0);
                    sample.NO3Units = Sample.NUnitsEnum.ppm;
                }

                // The elements below will be overlaid over other arrays of values so we want
                // to have missing values (double.NaN) used at the bottom of the profile.

                if (sample.CL != null)
                {
                    sample.CL = MapConcentration(sample.CL, sample.Thickness, thickness, double.NaN, allowMissingValues: true);
                }
                if (sample.EC != null)
                {
                    sample.EC = MapConcentration(sample.EC, sample.Thickness, thickness, double.NaN, allowMissingValues: true);
                }
                if (sample.ESP != null)
                {
                    sample.ESP = MapConcentration(sample.ESP, sample.Thickness, thickness, double.NaN, allowMissingValues: true);
                }
                if (sample.OC != null)
                {
                    sample.OC = MapConcentration(sample.OC, sample.Thickness, thickness, double.NaN, allowMissingValues: true);
                }
                if (sample.PH != null)
                {
                    sample.PH = MapConcentration(sample.PH, sample.Thickness, thickness, double.NaN, allowMissingValues: true);
                }
                sample.Thickness = thickness;
            }
        }
Exemple #24
0
        public void soilTest()
        {
            double  sand          = 17.3;
            double  limo          = 53.9;
            double  clay          = 28.8;
            double  organicMatter = 4.4;
            Horizon lHorizon      = new Horizon();

            lHorizon.Sand              = sand;
            lHorizon.Limo              = limo;
            lHorizon.Clay              = clay;
            lHorizon.OrganicMatter     = organicMatter;
            lHorizon.HorizonLayer      = "A";
            lHorizon.Order             = 0;
            lHorizon.HorizonLayerDepth = 5.3;

            Soil lSoil = new Soil();

            lSoil.HorizonList.Add(lHorizon);

            double pmp = lSoil.GetPermanentWiltingPoint(5);
            double cc  = lSoil.GetFieldCapacity(5);
            double ad  = lSoil.GetAvailableWaterCapacity(5);

            //double pmp10 = testSoil.GetPermanentWiltingPoint(10);
            double cc10 = lSoil.GetFieldCapacity(10);
            //double ad10 = testSoil.GetAvailableWaterCapacity(10);

            double pmp0 = lSoil.GetPermanentWiltingPoint(0);
            double cc0  = lSoil.GetFieldCapacity(0);
            double ad0  = lSoil.GetAvailableWaterCapacity(0);

            //RootDeepth between the border (0) and the HorizonDepth
            Assert.AreEqual(pmp, 16.002069999999989);
            Assert.AreEqual(cc, 34.1726);
            Assert.AreEqual(ad, 18.170530000000014);
            //RootDeepth outside the horizon
            //           Assert.AreEqual(pmp10, 0);
            Assert.AreEqual(cc10, 34.1726);
            //          Assert.AreEqual(ad10, 0);
            //RootDeepth = 0
            Assert.AreEqual(pmp0, 16.002069999999989);
            Assert.AreEqual(cc0, 34.1726);
            Assert.AreEqual(ad0, 18.170530000000014);
        }
Exemple #25
0
        /// <summary>Sets the water thickness.</summary>
        /// <param name="water">The water.</param>
        /// <param name="toThickness">To thickness.</param>
        /// <param name="soil">Soil</param>
        private static void SetWaterThickness(Water water, double[] toThickness, Soil soil)
        {
            if (!MathUtilities.AreEqual(toThickness, soil.Thickness))
            {
                bool needToConstrainCropLL = false;
                foreach (var cropName in soil.CropNames)
                {
                    var crop = soil.Crop(cropName);
                    crop.KL = MapConcentration(crop.KL, soil.Thickness, toThickness, MathUtilities.LastValue(crop.KL));
                    crop.XF = MapConcentration(crop.XF, soil.Thickness, toThickness, MathUtilities.LastValue(crop.XF));

                    if (crop is SoilCrop)
                    {
                        needToConstrainCropLL = true;

                        var soilCrop = crop as SoilCrop;
                        soilCrop.LL = MapConcentration(soilCrop.LL, soil.Thickness, toThickness, MathUtilities.LastValue(soilCrop.LL));
                    }
                }

                soil.BD        = MapConcentration(soil.BD, soil.Thickness, toThickness, MathUtilities.LastValue(soil.BD));
                soil.AirDry    = MapConcentration(soil.AirDry, soil.Thickness, toThickness, MathUtilities.LastValue(soil.AirDry));
                soil.LL15      = MapConcentration(soil.LL15, soil.Thickness, toThickness, MathUtilities.LastValue(soil.LL15));
                soil.DUL       = MapConcentration(soil.DUL, soil.Thickness, toThickness, MathUtilities.LastValue(soil.DUL));
                soil.SAT       = MapConcentration(soil.SAT, soil.Thickness, toThickness, MathUtilities.LastValue(soil.SAT));
                soil.KS        = MapConcentration(soil.KS, soil.Thickness, toThickness, MathUtilities.LastValue(soil.KS));
                soil.Thickness = toThickness;

                if (needToConstrainCropLL)
                {
                    foreach (ISoilCrop crop in water.Crops)
                    {
                        if (crop is SoilCrop)
                        {
                            var soilCrop = crop as SoilCrop;
                            // Ensure crop LL are between Airdry and DUL.
                            for (int i = 0; i < soilCrop.LL.Length; i++)
                            {
                                soilCrop.LL = MathUtilities.Constrain(soilCrop.LL, water.AirDry, water.DUL);
                            }
                        }
                    }
                }
            }
        }
Exemple #26
0
        public void AddPart_WithZeroCount_ChangesNothing()
        {
            // arrange
            var soil = new Soil()
            {
                Soil.Part <Sand>(1)
            };
            var copy = new Soil()
            {
                Soil.Part <Sand>(1)
            };

            // act
            soil.Add <Turf>(0);

            // assert
            Assert.AreEqual(copy, soil);
        }
Exemple #27
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            //add soil

            Soil soil = new Soil();

            soil.Name = soilNameText.Text;

            try
            {
                MainWindow.channel.AddSoil(soil);
                MessageBox.Show(soilNameText.Text + " added!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #28
0
        public void NH4UnitsSet(NUnitsEnum ToUnits, Soil Soil)
        {
            double[] BD = Soil.BDMapped(Thickness);

            if (ToUnits != NH4Units)
            {
                // convert the numbers
                if (ToUnits == NUnitsEnum.ppm)
                {
                    NH4 = NH4ppm(Soil);
                }
                else
                {
                    NH4 = NH4kgha(Soil);
                }
                NH4Units = ToUnits;
            }
        }
Exemple #29
0
        private void Button_build(object sender, RoutedEventArgs e)
        {
            IsNumber Isnumber = new IsNumber();

            Soil soil = new Soil(id, soilName.Text, soilTemp.Text, soilDiff.Text);

            if (Isnumber.isNumber(soilTemp.Text.Trim()) == false || Isnumber.isNumber(soilDiff.Text.Trim()) == false)
            {
                MessageBox.Show("输入格式有误");
            }
            else
            {
                SoilDAL dal = new SoilDAL();
                dal.addSoilData(soil);
                MessageBox.Show("添加成功");
                Close();
            }
        }
Exemple #30
0
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            try
            {
                Soil entity = await db.soil.byIdAsync(id);

                await db.soil.deleteAsync(entity);
                await writeEventAsync(entity.ToString(), LogEvent.del);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                await writeExceptionAsync(ex);

                return(RedirectToAction("Delete", new { id = id }));
            }
        }
Exemple #31
0
 //Reset
 /// <summary>
 /// Resets the soil.
 /// </summary>
 /// <param name="Consts">The consts.</param>
 /// <param name="Soil">The soil.</param>
 public void ResetSoil(Constants Consts, Soil Soil)
 {
     Constants = Consts;
     UseStartingValuesToInitialise(Soil);
 }
Exemple #32
0
        /// <summary>
        /// Uses the starting values to initialise.
        /// </summary>
        /// <param name="Soil">The soil.</param>
        private void UseStartingValuesToInitialise(Soil Soil)
        {
            //Soil Properties (NOT LAYERED)
            //*****************************

            //! flag to determine if Ks has been chosen for use.
            if (Soil.KS == null)
                using_ks = false;
            else
                using_ks = true;

            //From "SoilWater" node in the GUI
            //-------------------------------

            //summer

            SummerCona = Soil.SoilWater.SummerCona;
            SummerU = Soil.SoilWater.SummerU;
            SummerDate = Soil.SoilWater.SummerDate;

            //winter
            WinterCona = Soil.SoilWater.WinterCona;
            WinterU = Soil.SoilWater.WinterU;
            WinterDate = Soil.SoilWater.WinterDate;

            DiffusConst = Soil.SoilWater.DiffusConst;
            DiffusSlope = Soil.SoilWater.DiffusSlope;

            Salb = Soil.SoilWater.Salb;

            cn2_bare = Soil.SoilWater.CN2Bare;
            cn_red = Soil.SoilWater.CNRed;
            cn_cov = Soil.SoilWater.CNCov;

            slope = Soil.SoilWater.slope;
            discharge_width = Soil.SoilWater.discharge_width;
            catchment_area = Soil.SoilWater.catchment_area;

            if (Double.IsNaN(slope))
                slope = 0.0;

            if (Double.IsNaN(discharge_width))
                discharge_width = 0.0;

            if (Double.IsNaN(catchment_area))
                catchment_area = 0.0;

            max_pond = Soil.SoilWater.max_pond;

            //Soil "Profile" (LAYERED)
            //************************

            int i = 0;
            foreach (Layer lyr in this)
                {

                lyr.number = i + 1;

                //From "Water" node in GUI
                //-----------------------

                lyr.dlayer = Soil.Thickness[i]; //need to set dlayer first so the fractions below can be converted to their mm _dep versions
                lyr.bd = Soil.BD[i];
                lyr.sat = Soil.SAT[i];
                lyr.dul = Soil.DUL[i];
                lyr.ll15 = Soil.LL15[i];
                lyr.air_dry = Soil.AirDry[i];
                if (Soil.KS == null)      //can be blank in the node
                    lyr.ks = 0.0;               //turn off but using_ks flag stops this from mattering
                else
                    lyr.ks = Soil.KS[i];

                //From "SoilWater" node in the GUI
                //-------------------------------

                //(Use top level Soil instead of Soil.SoilWater so they are in standard layer thicknesses)

                if (Soil.SWCON == null)  //can be blank in the node
                    lyr.SWCON = 0.3;
                else
                    lyr.SWCON = Soil.SWCON[i];  //in standard thickness

                if (Soil.KLAT == null)   //can be blank in the node
                    lyr.KLAT = 0.0;             //turn off the lateral flow
                else
                    lyr.KLAT = Soil.KLAT[i];    //in standard thickness

                //From "InitWater" node or "SoilSample" node
                //------------------------------------------

                lyr.sw = Soil.InitialWaterVolumetric[i];

                i++;
                }
        }
Exemple #33
0
        private bool using_ks; //! flag to determine if Ks has been chosen for use. //sv- set in soilwat2_init() by checking if mwcon exists

        #endregion Fields

        #region Constructors

        //Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="SoilWaterSoil"/> class.
        /// </summary>
        /// <param name="Consts">The consts.</param>
        /// <param name="Soil">The soil.</param>
        /// <exception cref="System.Exception">Constructor for SoilWaterSoil failed because there are no layers</exception>
        public SoilWaterSoil(Constants Consts, Soil Soil)
        {
            //add all the layers
            if (Soil.Thickness != null)
                {
                layers = new List<Layer>();
                for (int i = 0; i < Soil.Thickness.Count(); i++)
                    {
                    Layer lyr = new Layer();
                    layers.Add(lyr);
                    }
                }
            else
                {
                throw new Exception("Constructor for SoilWaterSoil failed because there are no layers");
                }

            Constants = Consts;
            UseStartingValuesToInitialise(Soil);
        }