Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/PlLinesToWaternetConverterTests.cs =================================================================== diff -u -r2961 -r2962 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/PlLinesToWaternetConverterTests.cs (.../PlLinesToWaternetConverterTests.cs) (revision 2961) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/PlLinesToWaternetConverterTests.cs (.../PlLinesToWaternetConverterTests.cs) (revision 2962) @@ -1,4 +1,5 @@ -using System.Data; +using System; +using System.Data; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon; @@ -10,6 +11,49 @@ public class PlLinesToWaternetConverterTests { [Test] + [TestCase(0)] + [TestCase(0.01)] + [TestCase(10)] + public void ConvertPlLineToWaternet_PlLinesFullyDefinedAtOrBelowSoil1DProfile_ReturnsExpectedWaternet(double offsetFromBottomOfProfile) + { + // Setup + var random = new Random(21); + double leftCoordinate = random.NextDouble(); + double rightCoordinate = leftCoordinate + 1; + var penetrationLength = random.NextDouble(); + + SoilProfile1D soilProfile = CreateSoilProfile1DForTest(); + double bottomLevel = soilProfile.BottomLevel; + double plLineZCoordinate = bottomLevel - offsetFromBottomOfProfile; + + var plLines = new PlLines(); + PlLine plLine = plLines.Lines[PlLineType.Pl1]; + plLine.Points.Add(new PlLinePoint(leftCoordinate, plLineZCoordinate)); + plLine.Points.Add(new PlLinePoint(rightCoordinate, plLineZCoordinate)); + + plLine = plLines.Lines[PlLineType.Pl2]; + plLine.Points.Add(new PlLinePoint(leftCoordinate, plLineZCoordinate)); + plLine.Points.Add(new PlLinePoint(rightCoordinate, plLineZCoordinate)); + + plLine = plLines.Lines[PlLineType.Pl3]; + plLine.Points.Add(new PlLinePoint(leftCoordinate, plLineZCoordinate)); + plLine.Points.Add(new PlLinePoint(rightCoordinate, plLineZCoordinate)); + + plLine = plLines.Lines[PlLineType.Pl4]; + plLine.Points.Add(new PlLinePoint(leftCoordinate, plLineZCoordinate)); + plLine.Points.Add(new PlLinePoint(rightCoordinate, plLineZCoordinate)); + + // Call + var waternet = PlLinesToWaternetConverter.ConvertPlLineToWaternet(plLines, soilProfile, penetrationLength, leftCoordinate, rightCoordinate); + + // Assert + Assert.IsNull(waternet.PhreaticLine); + CollectionAssert.IsEmpty(waternet.HeadLineList); + CollectionAssert.IsEmpty(waternet.WaternetLineList); + } + + + [Test] public void TestConvertPlLinesToWaternet() { const double cDif = 0.0001; Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/PlLinesToWaternetConverter.cs =================================================================== diff -u -r2961 -r2962 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/PlLinesToWaternetConverter.cs (.../PlLinesToWaternetConverter.cs) (revision 2961) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/PlLinesToWaternetConverter.cs (.../PlLinesToWaternetConverter.cs) (revision 2962) @@ -24,19 +24,22 @@ ThrowWhenSoilProfile1DIsNull(soilProfile1D); var waternet = new Waternet { - IsGenerated = false, + IsGenerated = false }; var plLine1 = plLines.Lines[PlLineType.Pl1]; - waternet.PhreaticLine = new PhreaticLine(); - foreach (var plLinePoint in plLine1.Points) + if (plLine1 != null && !IsBelowSoilProfile(soilProfile1D, plLine1)) { - waternet.PhreaticLine.Points.Add(plLinePoint); + waternet.PhreaticLine = new PhreaticLine(); + foreach (var plLinePoint in plLine1.Points) + { + waternet.PhreaticLine.Points.Add(plLinePoint); + } } var plLine = plLines.Lines[PlLineType.Pl2]; var headLine = ConvertPlLineToHeadLine(plLine); - if (headLine != null) + if (headLine != null && !IsBelowSoilProfile(soilProfile1D, plLine)) { waternet.HeadLineList.Add(headLine); if (soilProfile1D.BottomAquiferLayer != null) @@ -50,7 +53,7 @@ plLine = plLines.Lines[PlLineType.Pl3]; headLine = ConvertPlLineToHeadLine(plLine); - if (headLine != null) + if (headLine != null && !IsBelowSoilProfile(soilProfile1D, plLine)) { waternet.HeadLineList.Add(headLine); if (soilProfile1D.BottomAquiferLayer != null) @@ -64,7 +67,7 @@ plLine = plLines.Lines[PlLineType.Pl4]; headLine = ConvertPlLineToHeadLine(plLine); - if (headLine != null) + if (headLine != null && !IsBelowSoilProfile(soilProfile1D, plLine)) { waternet.HeadLineList.Add(headLine); if (soilProfile1D.InBetweenAquiferLayer != null) @@ -79,6 +82,21 @@ return waternet; } + private static bool IsBelowSoilProfile(SoilProfile1D soilProfile, PlLine line) + { + double bottomSoilProfileLevel = soilProfile.BottomLevel; + + foreach (PlLinePoint point in line.Points) + { + if (point.Z <= bottomSoilProfileLevel) + { + return true; + } + } + + return false; + } + internal static HeadLine ConvertPlLineToHeadLine(PlLine plLine) { HeadLine headLine = null; @@ -129,7 +147,5 @@ throw new NoNullAllowedException(Resources.PlLinesToWaternetConverter_NoPlLinesDefined); } } - - } }