Example #1
0
        /// <summary>
        /// Creates a <see cref="SoilProfile"/> based on <paramref name="layersWithSoil"/>.
        /// </summary>
        /// <param name="layersWithSoil">The layer data to use in the <see cref="SoilProfile"/>.</param>
        /// <returns>A new <see cref="SoilProfile"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="layersWithSoil"/> is <c>null</c>.</exception>
        public static SoilProfile Create(IEnumerable <LayerWithSoil> layersWithSoil)
        {
            if (layersWithSoil == null)
            {
                throw new ArgumentNullException(nameof(layersWithSoil));
            }

            var profile = new SoilProfile();

            var alreadyCreatedPoints = new List <CSharpWrapperPoint2D>();
            var alreadyCreatedCurves = new List <Curve>();
            var alreadyCreatedLoops  = new List <Loop>();

            foreach (LayerWithSoil layerWithSoil in layersWithSoil)
            {
                profile.SoilSurfaces.Add(new SoilProfileSurface
                {
                    Name      = layerWithSoil.Soil.Name,
                    IsAquifer = layerWithSoil.IsAquifer,
                    Soil      = layerWithSoil.Soil,
                    Surface   = CreateSurface(layerWithSoil, alreadyCreatedPoints, alreadyCreatedCurves, alreadyCreatedLoops),
                    WaterPressureInterpolationModel = layerWithSoil.WaterPressureInterpolationModel
                });
            }

            profile.Geometry = CreateGeometry(profile);

            return(profile);
        }
Example #2
0
        private static Geometry CreateGeometry(SoilProfile profile)
        {
            var geometry = new Geometry
            {
                Surfaces = profile.SoilSurfaces.Select(s => s.Surface).ToArray()
            };

            geometry.Loops = geometry.Surfaces
                             .Select(s => s.OuterLoop)
                             .ToArray();

            geometry.Curves = geometry.Loops
                              .SelectMany(l => l.Curves)
                              .Distinct()
                              .ToArray();
            geometry.Points = geometry.Curves
                              .SelectMany(c => new[]
            {
                c.HeadPoint,
                c.EndPoint
            })
                              .Distinct()
                              .ToArray();

            geometry.Left   = geometry.Points.Min(p => p.X);
            geometry.Right  = geometry.Points.Max(p => p.X);
            geometry.Bottom = geometry.Points.Min(p => p.Z);

            return(geometry);
        }
Example #3
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var layers = new SoilLayer[0];
            var preconsolidationStresses = new PreconsolidationStress[0];

            // Call
            var profile = new SoilProfile(layers, preconsolidationStresses);

            // Assert
            Assert.AreSame(layers, profile.Layers);
            Assert.AreSame(preconsolidationStresses, profile.PreconsolidationStresses);
        }
Example #4
0
        public void Convert_WithSoilProfile_ReturnSoilProfile()
        {
            // Setup
            var random = new Random(22);

            MacroStabilityInwardsSoilLayer2D soilLayer1 = CreateRandomSoilLayer(22, new[]
            {
                CreateRandomSoilLayer(23, Enumerable.Empty <MacroStabilityInwardsSoilLayer2D>()),
                CreateRandomSoilLayer(24, Enumerable.Empty <MacroStabilityInwardsSoilLayer2D>())
            });

            MacroStabilityInwardsSoilLayer2D soilLayer2 = CreateRandomSoilLayer(25, new[]
            {
                CreateRandomSoilLayer(26, new[]
                {
                    CreateRandomSoilLayer(27, Enumerable.Empty <MacroStabilityInwardsSoilLayer2D>())
                })
            });

            var preconsolidationStress = new MacroStabilityInwardsPreconsolidationStress(new Point2D(random.NextDouble(), random.NextDouble()),
                                                                                         new VariationCoefficientLogNormalDistribution
            {
                Mean = (RoundedDouble)0.05,
                CoefficientOfVariation = random.NextRoundedDouble()
            });

            var profile = new MacroStabilityInwardsSoilProfileUnderSurfaceLine(
                new[]
            {
                soilLayer1,
                soilLayer2
            },
                new[]
            {
                preconsolidationStress
            });

            // Call
            SoilProfile soilProfile = SoilProfileConverter.Convert(profile);

            // Assert
            CalculatorInputAssert.AssertSoilProfile(profile, soilProfile);
        }
Example #5
0
    private static void sequestNutrient(ref Plant plant)
    {
        Segment     segment     = plant.segment;
        float       rootDepth   = plant.rootDepth; //might overwrite, but shouldn't
        float       rootRadius  = plant.rootWidth / 2;
        SoilProfile soilProfile = segment.soilProfile;

        foreach (SoilHorizon soilHorizon in soilProfile.soilHorizons)
        {
            float x1 = Mathf.Abs(soilHorizon.upperBound);
            float x2 = Mathf.Abs(soilHorizon.lowerBound);
            x2 = x2 > rootDepth ? x2 : rootDepth;
            float volume = volumeInDiagonalSubsection(x1, x2, rootRadius, rootDepth);
            foreach (string name in plant.plantNutrientManagers.Keys)
            {
                PlantNutrientManager nutrient = plant.plantNutrientManagers[name];
                nutrient.sequestNutrients(name, soilHorizon, volume);
            }
        }
    }
Example #6
0
        public void Convert_ValidShearStrengthModel_ReturnExpectedShearStrengthModel(MacroStabilityInwardsShearStrengthModel originalShearStrengthModel,
                                                                                     ShearStrengthModel expectedShearStrengthModel)
        {
            // Setup
            var profile = new MacroStabilityInwardsSoilProfileUnderSurfaceLine(new[]
            {
                new MacroStabilityInwardsSoilLayer2D(RingTestFactory.CreateRandomRing())
                {
                    Data =
                    {
                        ShearStrengthModel = originalShearStrengthModel
                    }
                }
            }, new MacroStabilityInwardsPreconsolidationStress[0]);

            // Call
            SoilProfile soilProfile = SoilProfileConverter.Convert(profile);

            // Assert
            Assert.AreEqual(expectedShearStrengthModel, soilProfile.Layers.First().ShearStrengthModel);
        }
Example #7
0
        public void Convert_SoilProfileWithSoilLayerWithEmptyName_ReturnSoilProfile()
        {
            // Setup
            MacroStabilityInwardsSoilLayer2D soilLayer = CreateRandomSoilLayer(22, Enumerable.Empty <MacroStabilityInwardsSoilLayer2D>());

            soilLayer.Data.MaterialName = string.Empty;

            var profile = new MacroStabilityInwardsSoilProfileUnderSurfaceLine(
                new[]
            {
                soilLayer
            },
                new IMacroStabilityInwardsPreconsolidationStress[0]);

            // Call
            SoilProfile soilProfile = SoilProfileConverter.Convert(profile);

            // Assert
            Assert.AreEqual(1, soilProfile.Layers.Count());
            Assert.AreEqual("Onbekend", soilProfile.Layers.First().MaterialName);
        }
Example #8
0
        public void Create_WithNeighbouringInnerLoops_ReturnSoilProfile2D()
        {
            // Setup
            var layer1Points = new[]
            {
                new Point2D(0, 0),
                new Point2D(0, 3),
                new Point2D(10, 3),
                new Point2D(10, 0)
            };

            var layer2Points = new[]
            {
                new Point2D(0, 3),
                new Point2D(0, 11),
                new Point2D(10, 11),
                new Point2D(10, 3)
            };

            var layer2Hole1Points = new[]
            {
                new Point2D(2, 5),
                new Point2D(2, 7),
                new Point2D(8, 7),
                new Point2D(8, 5)
            };

            var layer2Hole2Points = new[]
            {
                new Point2D(2, 7),
                new Point2D(2, 9),
                new Point2D(8, 9),
                new Point2D(8, 7)
            };

            var soil1 = new Soil
            {
                Name = "Clay"
            };

            var soil2 = new Soil
            {
                Name = "Sand"
            };

            var soil3 = new Soil
            {
                Name = "Nested clay"
            };

            var soil4 = new Soil
            {
                Name = "Nested sand"
            };

            var layerWithSoil1 = new LayerWithSoil(
                layer1Points,
                new Point2D[0][],
                soil1,
                false,
                WaterPressureInterpolationModel.Automatic);

            var layerWithSoil2 = new LayerWithSoil(
                layer2Points,
                new[]
            {
                layer2Hole1Points,
                layer2Hole2Points
            },
                soil2,
                true,
                WaterPressureInterpolationModel.Hydrostatic);

            var layerWithSoil3 = new LayerWithSoil(
                layer2Hole1Points,
                new Point2D[0][],
                soil3,
                false,
                WaterPressureInterpolationModel.Automatic);

            var layerWithSoil4 = new LayerWithSoil(
                layer2Hole2Points,
                new Point2D[0][],
                soil4,
                true,
                WaterPressureInterpolationModel.Hydrostatic);

            // Call
            SoilProfile profile = SoilProfileCreator.Create(new[]
            {
                layerWithSoil1,
                layerWithSoil2,
                layerWithSoil3,
                layerWithSoil4
            });

            // Assert

            #region Geometry

            var   outerLoopPoint1 = new CSharpWrapperPoint2D(0, 0);
            var   outerLoopPoint2 = new CSharpWrapperPoint2D(0, 3);
            var   outerLoopPoint3 = new CSharpWrapperPoint2D(10, 3);
            var   outerLoopPoint4 = new CSharpWrapperPoint2D(10, 0);
            var   outerLoopPoint5 = new CSharpWrapperPoint2D(0, 11);
            var   outerLoopPoint6 = new CSharpWrapperPoint2D(10, 11);
            Curve outerLoopCurve1 = CreateCurve(outerLoopPoint1, outerLoopPoint2);
            Curve outerLoopCurve2 = CreateCurve(outerLoopPoint2, outerLoopPoint3);
            Curve outerLoopCurve3 = CreateCurve(outerLoopPoint3, outerLoopPoint4);
            Curve outerLoopCurve4 = CreateCurve(outerLoopPoint4, outerLoopPoint1);
            Curve outerLoopCurve5 = CreateCurve(outerLoopPoint2, outerLoopPoint5);
            Curve outerLoopCurve6 = CreateCurve(outerLoopPoint5, outerLoopPoint6);
            Curve outerLoopCurve7 = CreateCurve(outerLoopPoint6, outerLoopPoint3);
            var   outerLoop1      = new Loop
            {
                Curves =
                {
                    outerLoopCurve1,
                    outerLoopCurve2,
                    outerLoopCurve3,
                    outerLoopCurve4
                }
            };
            var outerLoop2 = new Loop
            {
                Curves =
                {
                    outerLoopCurve5,
                    outerLoopCurve6,
                    outerLoopCurve7,
                    outerLoopCurve2
                }
            };

            var   innerLoopPoint1 = new CSharpWrapperPoint2D(2, 5);
            var   innerLoopPoint2 = new CSharpWrapperPoint2D(2, 7);
            var   innerLoopPoint3 = new CSharpWrapperPoint2D(8, 7);
            var   innerLoopPoint4 = new CSharpWrapperPoint2D(8, 5);
            var   innerLoopPoint5 = new CSharpWrapperPoint2D(2, 9);
            var   innerLoopPoint6 = new CSharpWrapperPoint2D(8, 9);
            Curve innerLoopCurve1 = CreateCurve(innerLoopPoint1, innerLoopPoint2);
            Curve innerLoopCurve2 = CreateCurve(innerLoopPoint2, innerLoopPoint3);
            Curve innerLoopCurve3 = CreateCurve(innerLoopPoint3, innerLoopPoint4);
            Curve innerLoopCurve4 = CreateCurve(innerLoopPoint4, innerLoopPoint1);
            Curve innerLoopCurve5 = CreateCurve(innerLoopPoint2, innerLoopPoint5);
            Curve innerLoopCurve6 = CreateCurve(innerLoopPoint5, innerLoopPoint6);
            Curve innerLoopCurve7 = CreateCurve(innerLoopPoint6, innerLoopPoint3);
            var   innerLoop1      = new Loop
            {
                Curves =
                {
                    innerLoopCurve1,
                    innerLoopCurve2,
                    innerLoopCurve3,
                    innerLoopCurve4
                }
            };
            var innerLoop2 = new Loop
            {
                Curves =
                {
                    innerLoopCurve5,
                    innerLoopCurve6,
                    innerLoopCurve7,
                    innerLoopCurve2
                }
            };

            CollectionAssert.AreEqual(new[]
            {
                outerLoopPoint1,
                outerLoopPoint2,
                outerLoopPoint3,
                outerLoopPoint4,
                outerLoopPoint5,
                outerLoopPoint6,
                innerLoopPoint1,
                innerLoopPoint2,
                innerLoopPoint3,
                innerLoopPoint4,
                innerLoopPoint5,
                innerLoopPoint6
            }, profile.Geometry.Points, new StabilityPointComparer());

            CollectionAssert.AreEqual(new[]
            {
                outerLoopCurve1,
                outerLoopCurve2,
                outerLoopCurve3,
                outerLoopCurve4,
                outerLoopCurve5,
                outerLoopCurve6,
                outerLoopCurve7,
                innerLoopCurve1,
                innerLoopCurve2,
                innerLoopCurve3,
                innerLoopCurve4,
                innerLoopCurve5,
                innerLoopCurve6,
                innerLoopCurve7
            }, profile.Geometry.Curves, new CurveComparer());

            CollectionAssert.AreEqual(new[]
            {
                outerLoop1,
                outerLoop2,
                innerLoop1,
                innerLoop2
            }, profile.Geometry.Loops, new LoopComparer());

            Assert.AreEqual(4, profile.SoilSurfaces.Count);
            Assert.AreEqual(4, profile.Geometry.Surfaces.Count);
            CollectionAssert.AreEqual(profile.SoilSurfaces.ToList()
                                      .Select(s => s.Surface),
                                      profile.Geometry.Surfaces);

            Assert.AreEqual(profile.Geometry.Points.Min(p => p.X), profile.Geometry.Left);
            Assert.AreEqual(profile.Geometry.Points.Max(p => p.X), profile.Geometry.Right);
            Assert.AreEqual(profile.Geometry.Points.Min(p => p.Z), profile.Geometry.Bottom);

            #endregion

            #region Surfaces

            SoilProfileSurface surface1 = profile.SoilSurfaces.ElementAt(0);
            Assert.AreSame(soil1, surface1.Soil);
            Assert.AreEqual(soil1.Name, surface1.Name);
            Assert.AreEqual(layerWithSoil1.IsAquifer, surface1.IsAquifer);
            Assert.AreEqual(layerWithSoil1.WaterPressureInterpolationModel, surface1.WaterPressureInterpolationModel);
            Assert.AreSame(profile.Geometry.Loops.ElementAt(0), surface1.Surface.OuterLoop);
            CollectionAssert.IsEmpty(surface1.Surface.InnerLoops);

            SoilProfileSurface surface2 = profile.SoilSurfaces.ElementAt(1);
            Assert.AreSame(soil2, surface2.Soil);
            Assert.AreEqual(soil2.Name, surface2.Name);
            Assert.AreEqual(layerWithSoil2.IsAquifer, surface2.IsAquifer);
            Assert.AreEqual(layerWithSoil2.WaterPressureInterpolationModel, surface2.WaterPressureInterpolationModel);
            Assert.AreSame(profile.Geometry.Loops.ElementAt(1), surface2.Surface.OuterLoop);
            CollectionAssert.AreEqual(new[]
            {
                profile.Geometry.Loops.ElementAt(2),
                profile.Geometry.Loops.ElementAt(3)
            }, surface2.Surface.InnerLoops);

            SoilProfileSurface surface3 = profile.SoilSurfaces.ElementAt(2);
            Assert.AreSame(soil3, surface3.Soil);
            Assert.AreEqual(soil3.Name, surface3.Name);
            Assert.AreEqual(layerWithSoil3.IsAquifer, surface3.IsAquifer);
            Assert.AreEqual(layerWithSoil3.WaterPressureInterpolationModel, surface3.WaterPressureInterpolationModel);
            Assert.AreSame(profile.Geometry.Loops.ElementAt(2), surface3.Surface.OuterLoop);
            CollectionAssert.IsEmpty(surface3.Surface.InnerLoops);

            SoilProfileSurface surface4 = profile.SoilSurfaces.ElementAt(3);
            Assert.AreSame(soil4, surface4.Soil);
            Assert.AreEqual(soil4.Name, surface4.Name);
            Assert.AreEqual(layerWithSoil4.IsAquifer, surface4.IsAquifer);
            Assert.AreEqual(layerWithSoil4.WaterPressureInterpolationModel, surface4.WaterPressureInterpolationModel);
            Assert.AreSame(profile.Geometry.Loops.ElementAt(3), surface4.Surface.OuterLoop);
            CollectionAssert.IsEmpty(surface4.Surface.InnerLoops);

            #endregion
        }
        /// <summary>
        /// Asserts whether <paramref name="actual"/> corresponds to <paramref name="original"/>.
        /// </summary>
        /// <param name="original">The original <see cref="IMacroStabilityInwardsSoilProfileUnderSurfaceLine"/>.</param>
        /// <param name="actual">The actual <see cref="SoilProfile"/>.</param>
        /// <exception cref="AssertionException">Thrown when <paramref name="actual"/>
        /// does not correspond to <paramref name="original"/>.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="original"/>
        /// contains an invalid value of the enum <see cref="MacroStabilityInwardsShearStrengthModel"/>.</exception>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="original"/>
        /// contains an unsupported value of <see cref="MacroStabilityInwardsShearStrengthModel"/>.</exception>
        public static void AssertSoilProfile(IMacroStabilityInwardsSoilProfileUnderSurfaceLine original, SoilProfile actual)
        {
            MacroStabilityInwardsSoilLayer2D[] expectedLayers = original.Layers.ToArray();
            SoilLayer[] actualLayers = actual.Layers.ToArray();

            IMacroStabilityInwardsPreconsolidationStress[] expectedPreconsolidationStresses = original.PreconsolidationStresses.ToArray();
            PreconsolidationStress[] actualPreconsolidationStresses = actual.PreconsolidationStresses.ToArray();

            AssertLayers(expectedLayers, actualLayers);
            AssertPreconsolidationStresses(expectedPreconsolidationStresses, actualPreconsolidationStresses);
        }
Example #10
0
 /// <summary>
 /// Asserts whether <paramref name="actual"/> is equal to <paramref name="expected"/>.
 /// </summary>
 /// <param name="expected">The expected <see cref="SoilProfile"/>.</param>
 /// <param name="actual">The actual <see cref="SoilProfile"/>.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="actual"/>
 /// is not equal to <paramref name="expected"/>.</exception>
 public static void AssertSoilProfile(SoilProfile expected, SoilProfile actual)
 {
     AssertSurfaces(expected.SoilSurfaces, actual.SoilSurfaces);
     AssertGeometry(expected.Geometry, actual.Geometry);
 }
 public override string ToString()
 {
     return(SoilProfile?.ToString() ?? string.Empty);
 }
Example #12
0
 private void evolveSoil(ref SoilProfile soilProfile)
 {
     foreach (SoilHorizon soilHorizon in soilProfile.soilHorizons)
     {
     }
 }