Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelInputTests.cs =================================================================== diff -u -r6526 -r6527 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelInputTests.cs (.../EngineToMacroStabilityKernelInputTests.cs) (revision 6526) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelInputTests.cs (.../EngineToMacroStabilityKernelInputTests.cs) (revision 6527) @@ -235,8 +235,11 @@ private static void CompareBishopCalculationGridSettings(SlipCircleDefinition expectedSlipCircleDefinition, SearchAreaConditionsType actualSearchAreaConditionsType) { - Assert.That(actualSearchAreaConditionsType.AutoSearchArea, Is.EqualTo(expectedSlipCircleDefinition.BishopSearchAreaDetermination == GridSizeDetermination.Automatic)); - Assert.That(actualSearchAreaConditionsType.AutoTangentLines, Is.False); + Assert.Multiple(() => + { + Assert.That(actualSearchAreaConditionsType.AutoSearchArea, Is.EqualTo(expectedSlipCircleDefinition.BishopSearchAreaDetermination == GridSizeDetermination.Automatic)); + Assert.That(actualSearchAreaConditionsType.AutoTangentLines, Is.False); + }); } private static void CompareUpliftVanCalculationGrid(UpliftVanCalculationGrid expectedSlipPlaneUpliftVan, Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r6525 -r6527 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 6525) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 6527) @@ -54,42 +54,22 @@ { SetupCurveSurfaceAssociations(); - var firstRegeneration = true; + RegenerateAllCurvesIntersection(); - while (true) - { - // break up all curves at intersections - RegenerateAllCurvesIntersection(); + newlyDetectedSurfaceList.Clear(); + geometryLoopDirections.Clear(); - newlyDetectedSurfaceList.Clear(); - geometryLoopDirections.Clear(); + int curvesCount = geometryData.Curves.Count; - int curvesCount = geometryData.Curves.Count; - - // initialise IsUsed of all curves to false - for (var index1 = 0; index1 < curvesCount; index1++) - { - SetIsUsed(geometryData.Curves[index1], CurveDirection.Forward, false); - SetIsUsed(geometryData.Curves[index1], CurveDirection.Reverse, false); - } - - // detect surfaces... the plaxis algorithm - int result = DetectSurfaces(firstRegeneration); - - if (result < 0) - { - if (!firstRegeneration) - { - break; - } - } - else - { - break; - } - - firstRegeneration = false; + // initialise IsUsed of all curves to false + for (var index1 = 0; index1 < curvesCount; index1++) + { + SetIsUsed(geometryData.Curves[index1], CurveDirection.Forward, false); + SetIsUsed(geometryData.Curves[index1], CurveDirection.Reverse, false); } + + // detect surfaces... the plaxis algorithm + DetectSurfaces(); } /// @@ -357,50 +337,74 @@ var doublePoints = new Dictionary(); // Make sure all points (as pointers) in curves are in the point list - foreach (GeometryCurve curve in geometryData.Curves) + EnsureAllPointsUsedInCurvesAreInPointsList(); + + // find double points (by location!) in point list and register them with original + IdentifyAndRegisterDoublePoints(doublePoints); + + // replace double points in curves with originals + ReplaceDoublePointReferencesInCurves(doublePoints); + + // remove curves which have the same head as end point, update surfaces that use these curves + RemoveInvalidCurvesAndUpdateSurfaces(); + + // removing curves from loops in surfaces may have created invalid surfaces, remove those here + RemoveInvalidSurfaces(); + + // remove double points from point list + RemoveDoublePointsAndUpdateEffectedPoints(doublePoints); + } + + private void RemoveDoublePointsAndUpdateEffectedPoints(Dictionary doublePoints) + { + foreach (Point2D point in doublePoints.Keys) { - if (!geometryData.Points.Contains(curve.HeadPoint)) + geometryData.Points.Remove(point); + + if (geometryData.NewlyEffectedPoints.Contains(point)) { - Point2D point = geometryData.GetPointAtLocation(curve.HeadPoint); - if (point != null) - { - curve.HeadPoint = point; - } - else - { - geometryData.Points.Add(curve.HeadPoint); - } + geometryData.NewlyEffectedPoints.Remove(point); } + } + } - if (!geometryData.Points.Contains(curve.EndPoint)) + private void RemoveInvalidSurfaces() + { + foreach (GeometrySurface surface in geometryData.Surfaces.ToArray()) + { + if (!surface.OuterLoop.HasArea()) { - Point2D point = geometryData.GetPointAtLocation(curve.EndPoint); - if (point != null) - { - curve.EndPoint = point; - } - else - { - geometryData.Points.Add(curve.EndPoint); - } + geometryData.Surfaces.Remove(surface); } } + } - // find double points (by location!) in point list and register them with original - for (var i = 0; i < geometryData.Points.Count; i++) + private void RemoveInvalidCurvesAndUpdateSurfaces() + { + foreach (GeometryCurve curve in geometryData.Curves.ToArray()) { - for (var j = 0; j < i; j++) + if (curve.HeadPoint == curve.EndPoint) { - if (i != j && geometryData.Points[i].LocationEquals(geometryData.Points[j])) + geometryData.Curves.Remove(curve); + if (geometryData.NewlyEffectedCurves.Contains(curve)) { - // register the double point and the original point - doublePoints[geometryData.Points[i]] = geometryData.Points[j]; - break; + geometryData.NewlyEffectedCurves.Remove(curve); } + + foreach (GeometrySurface surface in geometryData.Surfaces) + { + surface.OuterLoop.CurveList.Remove(curve); + foreach (GeometryLoop loop in surface.InnerLoops) + { + loop.CurveList.Remove(curve); + } + } } } + } - // replace double points in curves with originals + private void ReplaceDoublePointReferencesInCurves(Dictionary doublePoints) + { foreach (Point2D doublePoint in doublePoints.Keys) { foreach (GeometryCurve curve in geometryData.Curves) @@ -429,51 +433,57 @@ } } } + } - // remove curves which have the same head as end point - foreach (GeometryCurve curve in geometryData.Curves.ToArray()) + private void IdentifyAndRegisterDoublePoints(Dictionary doublePoints) + { + for (var i = 0; i < geometryData.Points.Count; i++) { - if (curve.HeadPoint == curve.EndPoint) + for (var j = 0; j < i; j++) { - geometryData.Curves.Remove(curve); - if (geometryData.NewlyEffectedCurves.Contains(curve)) + if (i != j && geometryData.Points[i].LocationEquals(geometryData.Points[j])) { - geometryData.NewlyEffectedCurves.Remove(curve); + // register the double point and the original point + doublePoints[geometryData.Points[i]] = geometryData.Points[j]; + break; } - - foreach (GeometrySurface surface in geometryData.Surfaces) - { - surface.OuterLoop.CurveList.Remove(curve); - foreach (GeometryLoop loop in surface.InnerLoops) - { - loop.CurveList.Remove(curve); - } - } } } + } - // removing curves from loops in surfaces may have created invalid surfaces, remove those here - foreach (GeometrySurface surface in geometryData.Surfaces.ToArray()) + private void EnsureAllPointsUsedInCurvesAreInPointsList() + { + foreach (GeometryCurve curve in geometryData.Curves) { - if (!surface.OuterLoop.HasArea()) + if (!geometryData.Points.Contains(curve.HeadPoint)) { - geometryData.Surfaces.Remove(surface); + Point2D point = geometryData.GetPointAtLocation(curve.HeadPoint); + if (point != null) + { + curve.HeadPoint = point; + } + else + { + geometryData.Points.Add(curve.HeadPoint); + } } - } - // remove double points from point list - foreach (Point2D point in doublePoints.Keys) - { - geometryData.Points.Remove(point); - - if (geometryData.NewlyEffectedPoints.Contains(point)) + if (!geometryData.Points.Contains(curve.EndPoint)) { - geometryData.NewlyEffectedPoints.Remove(point); + Point2D point = geometryData.GetPointAtLocation(curve.EndPoint); + if (point != null) + { + curve.EndPoint = point; + } + else + { + geometryData.Points.Add(curve.EndPoint); + } } } } - private int DetectSurfaces(bool firstRegeneration) + private void DetectSurfaces() { try { @@ -534,7 +544,7 @@ { // the curve wasn't added bcos the curve-direction pair was already present in loop. // problem case - break here, else we'd get aValue1 hang! - throw new Exception("The curve could not be added to the loop"); + throw new ArgumentException("DetectSurfaces: The curve could not be added to the loop"); } Point2D curveEndPoint = currentCurve.GetEndPoint(currentCurveDirection); @@ -563,7 +573,7 @@ if (attachedCurveList.Count == 0) // no curves found { - throw new Exception("No connected Curve found"); + throw new ArgumentException("DetectSurfaces: No connected Curve found"); } // we have aValue1 set of curves, find the one that turns right the most @@ -608,19 +618,14 @@ } // create surfaces! - return CreateSurfaces(newLoopList); + CreateSurfaces(newLoopList); } #if DEBUG catch (Exception ex) { Debug.WriteLine(ex); - return 0; + } -#else - catch - { - return 0; - } #endif }