Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs =================================================================== diff -u -r6557 -r6572 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs (.../SoilProfile2DSurfaceLineHelper.cs) (revision 6557) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs (.../SoilProfile2DSurfaceLineHelper.cs) (revision 6572) @@ -99,14 +99,19 @@ var oldSurfaces = new List(); oldSurfaces.AddRange(soilProfile2D.Surfaces); //GeometryExporter.ExportToFile(soilProfile2D.Geometry, GeometryExporter.VisualizationFolder + "_oldSurf_" +"GeometryStart.txt"); -//GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + GeometryExporter.ExportJasonFile, clonedProfile.Geometry, surfaceLine); - var result = new SoilProfile2D(); - result.Name = soilProfile2D.Name; - result.Geometry = CreateNewGeometryForSoilProfile2DByCombiningItsGeometryWithSurfaceLine(clonedSurfaceLine, clonedProfile.Geometry); -//GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + GeometryExporter.ExportJasonFile, result.Geometry, surfaceLine); +//GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + GeometryExporter.ExportJasonFile, +// clonedProfile.Geometry, surfaceLine); + var result = new SoilProfile2D + { + Name = soilProfile2D.Name, + Geometry = CreateNewGeometryForSoilProfile2DByCombiningItsGeometryWithSurfaceLine(clonedSurfaceLine, + clonedProfile.Geometry) + }; +//GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + GeometryExporter.ExportJasonFile, +// result.Geometry, surfaceLine); RemoveGeometryDataOfSoilProfileAboveSurfaceLine(clonedSurfaceLine, ref result); //GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + GeometryExporter.ExportJasonFile, result.Geometry, surfaceLine); - ReconstructSurfaces(ref result, clonedSurfaceLine, oldSurfaces, defaultSoil); + ReconstructSurfaces(ref result, clonedProfile.Geometry.Left, clonedProfile.Geometry.Right, oldSurfaces, defaultSoil); //GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + GeometryExporter.ExportJasonFile, result.Geometry, surfaceLine); ReconstructPreConsolidations(ref result, clonedProfile); result.Geometry.Rebox(); @@ -341,7 +346,7 @@ result.DeleteLoosePoints(); } - private static void ReconstructSurfaces(ref SoilProfile2D result, GeometryPointString surfaceLine, + private static void ReconstructSurfaces(ref SoilProfile2D result, double oldLeftLimit, double oldRightLimit, List oldSurfaces, Soil defaultSoil) { result.Surfaces.Clear(); @@ -352,7 +357,7 @@ GeometrySurface = surface, Soil = defaultSoil }; - + SoilLayer2D layerFromOldSurfaces = SoilProfile2D.DetermineOriginalLayerFromOldSurfaces(surface, oldSurfaces); if (layerFromOldSurfaces != null && layerFromOldSurfaces.Soil != null) { @@ -363,7 +368,8 @@ if (layerFromOldSurfaces == null) { - SoilLayer2D oldLayer = DetermineLayerIfSurfaceIsLeftOrRightOfOldSurfaces(surface, oldSurfaces); + SoilLayer2D oldLayer = DetermineLayerIfSurfaceIsLeftOrRightOfOldSurfaces(surface, oldSurfaces, oldLeftLimit, + oldRightLimit); if (oldLayer != null) { @@ -393,35 +399,51 @@ } private static SoilLayer2D DetermineLayerIfSurfaceIsLeftOrRightOfOldSurfaces(GeometrySurface surface, - List oldSurfaces) + List oldSurfaces, double oldLeftLimit, double oldRightLimit) { Point2D point = surface.DetermineValidTestPointBasedOnNewSurface(); + // Check if the new surface is left or right of the old surfaces, if not just return null. if (!SoilProfile2D.IsSurfaceLeftOrRightOfOldSurfaces(point, oldSurfaces)) { return null; } - - double[] xMin = surface.OuterLoop.Points.Select(p => p.X).OrderBy(x => x).Distinct().ToArray(); - double[] zMin = surface.OuterLoop.Points.Select(p => p.Z).OrderBy(z => z).Distinct().ToArray(); - var leftPoint = new Point2D - { - X = xMin[0] - 0.1, - Z = zMin[0] + 0.1 - }; - SoilLayer2D soilLayer = SoilProfile2D.DetermineOldSurfaceFromTestPoint(oldSurfaces, leftPoint); - if (soilLayer != null) + SoilLayer2D soilLayer = null; + // Check if first two left points of the new surface have identical x values (they are vertical). + // If so, check these points are on the right boundary of the original geometry (so before extending) + // Then this surface is extended to the right side of the geometry and only then use material to its left. + Point2D[] leftPoints = surface.OuterLoop.Points.Select(p => p).OrderBy(x => x).ToArray(); + Point2D leftPoint = leftPoints.First(); + Point2D secondLeftPoint = leftPoints.Skip(1).First(); + if (leftPoint.X.IsNearEqual(oldRightLimit) && leftPoint.X.IsNearEqual(secondLeftPoint.X)) { - return soilLayer; + var newLeftPoint = new Point2D + { + X = leftPoint.X - 0.1, + Z = (leftPoint.Z + secondLeftPoint.Z) * 0.5 + }; + soilLayer = SoilProfile2D.DetermineOldSurfaceFromTestPoint(oldSurfaces, newLeftPoint); + if (soilLayer != null) + { + return soilLayer; + } } - - var rightPoint = new Point2D + + // Check if first two right points of the new surface have identical x values (they are vertical). + // If so, check these points are on the left boundary of the original geometry (so before extending) + // Then this surface is extended to the left side of the geometry and only then use material to its right. + Point2D rightPoint = leftPoints.Last(); + Point2D secondRightPoint = leftPoints.Skip(leftPoints.Length - 2).First(); + if (rightPoint.X.IsNearEqual(oldLeftLimit) && rightPoint.X.IsNearEqual(secondRightPoint.X)) { - X = xMin[^1] + 0.1, - Z = zMin[0] + 0.1 - }; + var newRightPoint = new Point2D + { + X = rightPoint.X + 0.1, + Z = (rightPoint.Z + secondRightPoint.Z) * 0.5 + }; + soilLayer = SoilProfile2D.DetermineOldSurfaceFromTestPoint(oldSurfaces, newRightPoint); + } - soilLayer = SoilProfile2D.DetermineOldSurfaceFromTestPoint(oldSurfaces, rightPoint); return soilLayer; }