Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilSurfaceProfileTests.cs =================================================================== diff -u -r3246 -r3247 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilSurfaceProfileTests.cs (.../SoilSurfaceProfileTests.cs) (revision 3246) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/SoilSurfaceProfileTests.cs (.../SoilSurfaceProfileTests.cs) (revision 3247) @@ -33,7 +33,7 @@ public class SoilSurfaceProfileTests { [Test] - public void ConvertToSoilProfile2D_WithSurfaceLineFullyAboveSoilLayers_SetsCorrectSurfacesAndGeometry() + public void ConvertToSoilProfile2D_WithSurfaceLineFullyAboveSoilLayers_ReturnsExpectedSoilProfile2D() { // Setup const string bottomLayerName = "BottomLayer"; @@ -111,9 +111,76 @@ }, bottomSoilLayer2D.GeometrySurface.OuterLoop.CurveList); } + [Test] + public void ConvertToSoilProfile2D_WithLayerFullyAboveSurfaceLine_ReturnsExpectedSoilProfile2D() + { + // Setup + const string bottomLayerName = "BottomLayer"; + const string middleLayerName = "MiddleLayer"; + const string topLayerName = "TopLayer"; + + SoilLayer1D irrelevantLayer = CreateSoilLayer(0, "Does not matter"); + SoilLayer1D bottomLayer = CreateSoilLayer(-5, bottomLayerName); + SoilLayer1D middleLayer = CreateSoilLayer(-2, middleLayerName); + + var profile = new SoilProfile1D + { + BottomLevel = -10 + }; + profile.Layers.Add(bottomLayer); + profile.Layers.Add(middleLayer); + profile.Layers.Add(irrelevantLayer); + + SurfaceLine2 surfaceLine = CreateSurfaceLine(new[] + { + new GeometryPoint(0, -5), + new GeometryPoint(5, -3), + new GeometryPoint(10, -5) + }); + + var soilSurfaceProfile = new SoilSurfaceProfile + { + SoilProfile = profile, + SurfaceLine2 = surfaceLine, + DikeEmbankmentMaterial = new Soil + { + Name = topLayerName + } + }; + + // Call + SoilProfile2D soilProfile2D = soilSurfaceProfile.ConvertToSoilProfile2D(); + + // Assert + var soilLayer2Ds = soilProfile2D.Surfaces; + Assert.That(soilLayer2Ds, Has.Count.EqualTo(2)); + + SoilLayer2D middleSoilLayer2D = soilLayer2Ds.Single(l => string.Equals(l.Name, middleLayerName)); + Assert.That(middleSoilLayer2D.Soil, Is.SameAs(middleLayer.Soil)); + AssertGeometry(new[] + { + new GeometryCurve(new Point2D(0, -5), new Point2D(5, -3)), + new GeometryCurve(new Point2D(5, -3), new Point2D(10, -5)), + new GeometryCurve(new Point2D(10, -5), new Point2D(5, -5)), + new GeometryCurve(new Point2D(5, -5), new Point2D(0, -5)) + }, middleSoilLayer2D.GeometrySurface.OuterLoop.CurveList); + + SoilLayer2D bottomSoilLayer2D = soilLayer2Ds.Single(l => string.Equals(l.Name, bottomLayerName)); + Assert.That(bottomSoilLayer2D.Soil, Is.SameAs(bottomLayer.Soil)); + AssertGeometry(new[] + { + new GeometryCurve(new Point2D(0, -5), new Point2D(5, -5)), + new GeometryCurve(new Point2D(5, -5), new Point2D(10, -5)), + new GeometryCurve(new Point2D(10, -5), new Point2D(10, -10)), + new GeometryCurve(new Point2D(10, -10), new Point2D(5, -10)), + new GeometryCurve(new Point2D(5, -10), new Point2D(0, -10)), + new GeometryCurve(new Point2D(0, -10), new Point2D(0, -5)) + }, bottomSoilLayer2D.GeometrySurface.OuterLoop.CurveList); + } + [Test] //Todo #Bka This succeeds locally in the NoExternals version! So Maybe there failuremechanism or C#wrapper is out of date. Update 1 by 1 to find out [Category(Categories.WorkInProgress)] - public void ConvertToSoilProfile2D_WithSurfaceLineFullyEnvelopedByTopSoilLayer_SetsCorrectSurfacesAndGeometry() + public void ConvertToSoilProfile2D_WithSurfaceLineFullyEnvelopedByTopSoilLayer_ReturnsExpectedSoilProfile2D() { // Setup const string bottomLayerName = "BottomLayer"; @@ -179,7 +246,7 @@ [Test] [Category(Categories.WorkInProgress)] - public void ConvertToSoilProfile2D_WithSurfaceLinePartiallyEnvelopedByTopSoilLayer_SetsCorrectSurfacesAndGeometry() + public void ConvertToSoilProfile2D_WithSurfaceLinePartiallyEnvelopedByTopSoilLayer_ReturnsExpectedSoilProfile2D() { // Setup const string bottomLayerName = "BottomLayer"; Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilSurfaceProfile.cs =================================================================== diff -u -r3246 -r3247 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilSurfaceProfile.cs (.../SoilSurfaceProfile.cs) (revision 3246) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilSurfaceProfile.cs (.../SoilSurfaceProfile.cs) (revision 3247) @@ -374,10 +374,9 @@ soilLayers.Insert(0, new SoilLayer1D(DikeEmbankmentMaterial, maxZCoordinateSurfaceLine)); } - // TODO: Determine if a layer lies fully above the surface line --> If yes, remove it from the layers to convert - copiedSoilProfile.EnsureLastLayerHasHeight(); - return copiedSoilProfile.Layers; + + return copiedSoilProfile.Layers.Where(l => !IsLayerAboveSurfaceLine(l, surfaceLine)); } private static IEnumerable CreateLayerData(IEnumerable soilLayers, @@ -404,6 +403,11 @@ return surfaceLine.Geometry.GetMinZ() > soilLayer.TopLevel; } + private static bool IsLayerAboveSurfaceLine(SoilLayer1D soilLayer, SurfaceLine2 surfaceLine2) + { + return soilLayer.BottomLevel > surfaceLine2.Geometry.GetMaxZ(); + } + private static LayerData CreateSurfaceLineWideSoilLayer(SoilLayer1D soilLayer, IEnumerable xCoordinates) { // A single square definition does not suffice for the area definition. The