public void TestWaterTable() { SoilModel soil = new SoilModel(); APSIM.Shared.Soils.Soil soilProperties = Setup(); APSIMReadySoil.Create(soilProperties); WaterTableModel waterTable = new WaterTableModel(); SetLink(soil, "properties", soilProperties); SetLink(waterTable, "soil", soil); double[] DUL = MathUtilities.Multiply(soilProperties.Water.DUL, soilProperties.Water.Thickness); double[] SAT = MathUtilities.Multiply(soilProperties.Water.SAT, soilProperties.Water.Thickness); // Profile at DUL. Essentially water table is below profile. soil.Water = DUL; Assert.AreEqual(waterTable.Value(), 1600); // Put a saturated layer at index 3. soil.Water[3] = SAT[3]; Assert.AreEqual(waterTable.Value(), 700); // Put a saturated layer at index 3 and a drainable layer at index 2. soil.Water[2] = (DUL[2] + SAT[2]) / 2; soil.Water[3] = SAT[3]; Assert.AreEqual(waterTable.Value(), 250); }
public void TestUnsaturatedFlow() { SoilModel soil = new SoilModel(); APSIM.Shared.Soils.Soil soilProperties = Setup(); APSIMReadySoil.Create(soilProperties); UnsaturatedFlowModel unsaturatedFlow = new UnsaturatedFlowModel(); SetLink(soil, "properties", soilProperties); SetLink(unsaturatedFlow, "soil", soil); unsaturatedFlow.DiffusConst = 88; unsaturatedFlow.DiffusSlope = 35.4; // Profile at DUL. soil.Water = MathUtilities.Multiply(soilProperties.Water.DUL, soilProperties.Water.Thickness); double[] flow = unsaturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flow, new double[] { 0, 0, 0, 0, 0, 0 })); // Profile at SAT. soil.Water = MathUtilities.Multiply(soilProperties.Water.SAT, soilProperties.Water.Thickness); flow = unsaturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flow, new double[] { 0, 0, 0, 0, 0, 0 })); // Force some unsaturated flow by reducing the water to 0.8 of SAT. soil.Water = MathUtilities.Multiply_Value(soil.Water, 0.8); flow = unsaturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flow, new double[] { 0.52148, -0.38359, -0.16771, -0.07481, 0, 0 })); }
public void TestLateralFlow() { APSIM.Shared.Soils.Soil soilProperties = Setup(); soilProperties.Samples.Clear(); // Setup our objects with links. SoilModel soil = new SoilModel(); LateralFlowModel lateralFlow = new LateralFlowModel(); SetLink(soil, "properties", soilProperties); SetLink(soil, "lateralFlowModel", lateralFlow); SetLink(lateralFlow, "soil", soil); // Set initial water to full. soilProperties.InitialWater = new InitialWater(); soilProperties.InitialWater.FractionFull = 1.0; APSIMReadySoil.Create(soilProperties); soil.Water = MathUtilities.Multiply(soilProperties.Water.SW, soilProperties.Water.Thickness); // No inflow, so there should be no outflow. lateralFlow.InFlow = null; Assert.AreEqual(lateralFlow.Values.Length, 0); // Profile is full so adding in flow will produce out flow. lateralFlow.InFlow = new double[] { 9, 9, 9, 9, 9, 9 }; lateralFlow.KLAT = MathUtilities.CreateArrayOfValues(8.0, soilProperties.Water.Thickness.Length); Assert.IsTrue(MathUtilities.AreEqual(lateralFlow.Values, new double[] { 0.45999, 0.80498, 0.80498, 0.80498, 0.80498, 0.80498 })); // Set initial water to empty. Out flow should be zeros. soilProperties.InitialWater = new InitialWater(); soilProperties.InitialWater.FractionFull = 0.0; APSIMReadySoil.Create(soilProperties); soil.Water = MathUtilities.Multiply(soilProperties.Water.SW, soilProperties.Water.Thickness); Assert.IsTrue(MathUtilities.AreEqual(lateralFlow.Values, new double[] { 0, 0, 0, 0, 0, 0 })); }
void initialize() { crop = new CropModel(); soil = new SoilModel(); crop.initialize(); soil.initialize(); // set starting date & simulation config this.startdoy = 120; this.lastdoy = 330; }
public double GetTangentModulus(double ratio) { double stress = ratio * SoilModel.GetFailureStress(); var solver = new NewtonSolver(x => SoilModel.GetDeviatoricStress(x) - stress, 0); double eps = solver.Solve(); var derivative = new Derivative(x => SoilModel.GetDeviatoricStress(x), DerivativeAccuracy); return(derivative.GetFirstDerivative(eps)); }
public double GetSecantModulus(double ratio) { double stress = ratio * SoilModel.GetFailureStress(); var solver = new NewtonSolver(x => SoilModel.GetDeviatoricStress(x) - stress, 0); double eps = solver.Solve(); if (eps == 0) { throw new Exception(); } return(stress / eps); }
// Get: api/Soils/id public IHttpActionResult GetSoilById(string id) { SoilModel Soil = null; using (SoilCareEntities db = new SoilCareEntities()) { Soil = db.Soils.Include("Plants") .Where(s => s.Soil_id.Equals(id)) .Select(AutoMapper.Mapper.Map <Soil, SoilModelDetail>) .FirstOrDefault <SoilModelDetail>(); } if (Soil == null) { return(NotFound()); } return(Ok(Soil)); }
public void TestSaturatedFlow() { SoilModel soil = new SoilModel(); APSIM.Shared.Soils.Soil soilProperties = Setup(); APSIMReadySoil.Create(soilProperties); SaturatedFlowModel saturatedFlow = new SaturatedFlowModel(); SetLink(soil, "properties", soilProperties); SetLink(saturatedFlow, "soil", soil); saturatedFlow.SWCON = new double[] { 0.3, 0.3, 0.3, 0.3, 0.3, 0.3 }; // Profile at DUL. soil.Water = MathUtilities.Multiply(soilProperties.Water.DUL, soilProperties.Water.Thickness); double[] flux = saturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flux, new double[] { 0, 0, 0, 0, 0, 0 })); // Profile at SAT. soil.Water = MathUtilities.Multiply(soilProperties.Water.SAT, soilProperties.Water.Thickness); flux = saturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flux, new double[] { 1.05, 2.85, 4.64999, 6.45, 8.25, 10.05 })); // Use the KS method soilProperties.Water.KS = new double[] { 1000, 300, 20, 100, 100, 100 }; flux = saturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flux, new double[] { 1.05, 1.8000, 1.8000, 1.8000, 1.8000, 1.8000 })); Assert.AreEqual(saturatedFlow.backedUpSurface, 0); // Use the KS method, water above SAT. soilProperties.Water.KS = new double[] { 1000, 300, 20, 100, 100, 100 }; MathUtilities.AddValue(soil.Water, 10); // add 5 mm of water into each layer. flux = saturatedFlow.Values; Assert.IsTrue(MathUtilities.AreEqual(flux, new double[] { 1.05, 1.8000, 1.8000, 1.8000, 1.8000, 1.8000 })); }
public void TestRunoff() { SoilModel soil = new SoilModel(); APSIM.Shared.Soils.Soil soilProperties = Setup(); APSIMReadySoil.Create(soilProperties); MockWeather weather = new MockWeather(); weather.Rain = 100; MockIrrigation irrigation = new MockIrrigation(); irrigation.IrrigationApplied = 0; MockSurfaceOrganicMatter surfaceOrganicMatter = new MockSurfaceOrganicMatter(); surfaceOrganicMatter.Cover = 0.1; CNReductionForCover reductionForCover = new CNReductionForCover(); List <ICanopy> canopies = new List <ICanopy>(); CNReductionForTillage reductionForTillage = new CNReductionForTillage(); RunoffModel runoff = new RunoffModel(); runoff.CN2Bare = 70; // setup links SetLink(soil, "properties", soilProperties); SetLink(soil, "runoffModel", runoff); SetLink(soil, "weather", weather); SetLink(soil, "irrigation", irrigation); SetLink(runoff, "soil", soil); SetLink(runoff, "reductionForCover", reductionForCover); SetLink(runoff, "reductionForTillage", reductionForTillage); SetLink(reductionForCover, "surfaceOrganicMatter", surfaceOrganicMatter); SetLink(reductionForCover, "canopies", canopies); SetLink(reductionForTillage, "weather", weather); // Empty profile. soil.Water = MathUtilities.Multiply(soilProperties.Water.LL15, soilProperties.Water.Thickness); // Profile is empty - should be small amount of runoff. Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value(), 5.60815)); // Full profile - should be a lot more runoff. soil.Water = MathUtilities.Multiply(soilProperties.Water.DUL, soilProperties.Water.Thickness); Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value(), 58.23552)); // Test CN reduction due to canopy. Tests the Curve Number vs Cover graph. // Cover is 10%, reduction is 2.5 surfaceOrganicMatter.Cover = 0.1; Assert.IsTrue(MathUtilities.FloatsAreEqual(reductionForCover.Value(), 2.49999)); // Cover is 80%, reduction is 20 surfaceOrganicMatter.Cover = 0.8; Assert.IsTrue(MathUtilities.FloatsAreEqual(reductionForCover.Value(), 20.0)); // Test Runoff vs Rainfall graph i.e. effect of different curve numbers. surfaceOrganicMatter.Cover = 0.0; runoff.CN2Bare = 60; Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value(), 48.18584)); runoff.CN2Bare = 75; Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value(), 68.16430)); runoff.CN2Bare = 85; Assert.IsTrue(MathUtilities.FloatsAreEqual(runoff.Value(), 81.15006)); }