Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityCommonHelper.cs =================================================================== diff -u -r6677 -r7060 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityCommonHelper.cs (.../MacroStabilityCommonHelper.cs) (revision 6677) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityCommonHelper.cs (.../MacroStabilityCommonHelper.cs) (revision 7060) @@ -551,10 +551,11 @@ ValidateForCombineSoilProfile2DWithSurfaceLine(subSoilScenario, surfaceLine2, dikeEmbankmentSoil); subSoilScenario.SoilProfile2D = SoilProfile2DSurfaceLineHelper.CombineSurfaceLineWithSoilProfile2D(surfaceLine2.Geometry, subSoilScenario.SoilProfile2D, dikeEmbankmentSoil); - CorrectSurfacelinePointsForGeometryCoordinates(subSoilScenario.SoilProfile2D.Geometry, surfaceLine2); + CorrectSurfaceLinePointsForGeometryCoordinates(subSoilScenario.SoilProfile2D.Geometry, surfaceLine2); + CheckIfAllLayersWereCorrectlyGenerated(subSoilScenario.SoilProfile2D, surfaceLine2); } - private static void CorrectSurfacelinePointsForGeometryCoordinates(GeometryData geometry, SurfaceLine2 surfaceLine) + private static void CorrectSurfaceLinePointsForGeometryCoordinates(GeometryData geometry, SurfaceLine2 surfaceLine) { foreach (Point2D surfaceLinePoint in surfaceLine.Geometry.Points) { @@ -569,6 +570,25 @@ RemovePointsAtSameXLocation(surfaceLine); } + private static void CheckIfAllLayersWereCorrectlyGenerated(SoilProfile2D soilProfile2D, SurfaceLine2 surfaceLine) + { + for (var i = 0; i < surfaceLine.Geometry.Points.Count; i++) + { + Point2D surfaceLinePoint = surfaceLine.Geometry.Points[i]; + SoilProfile1D geometry1D = soilProfile2D.GetSoilProfile1D(surfaceLinePoint.X); + bool profileContainsHole = geometry1D.Layers.Any(layer => layer.Soil == null); + // Check if the top layer is generated correctly. + // Do not check the first and last points because the 1D profile is not exactly at the X position. + bool topLayerNotGenerated = i > 0 && i < surfaceLine.Geometry.Points.Count - 1 && + Math.Abs(geometry1D.TopLevel - surfaceLinePoint.Z) > 2 * GeometryConstants.Accuracy; + + if (profileContainsHole || topLayerNotGenerated) + { + throw new Exception(Resources.MacroStabilityKernelWrapper_SoilProfile2DHasMissingLayers); + } + } + } + /// /// Removes points with same X coordinates and different Z ///