Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj =================================================================== diff -u -r425a1030cf1f383e0a8f5cbd712c52c5cc2d3369 -r257b5b8c4e053ff875f75e0940a0f9d8775ef083 --- Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj (.../Ringtoets.Piping.Data.csproj) (revision 425a1030cf1f383e0a8f5cbd712c52c5cc2d3369) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/Ringtoets.Piping.Data.csproj (.../Ringtoets.Piping.Data.csproj) (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -68,6 +68,7 @@ + Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModelExtensions.cs =================================================================== diff -u --- Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModelExtensions.cs (revision 0) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilModelExtensions.cs (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -0,0 +1,71 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Collections.Generic; +using System.Linq; +using Core.Common.Base.Geometry; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Data +{ + /// + /// Extension methods dealing with instances. + /// + public static class StochasticSoilModelExtensions + { + /// + /// Indicates whether a stochastic soil model intersects with a surface line. + /// + /// The stochastic soil model used to match a surface line. + /// The surface line used to match a stochastic soil model. + /// true when the intersects with the ; + /// false otherwise. + /// Thrown when any input parameter is null. + public static bool IntersectsWithSurfaceLineGeometry(this StochasticSoilModel stochasticSoilModel, + RingtoetsPipingSurfaceLine surfaceLine) + { + if (stochasticSoilModel == null) + { + throw new ArgumentNullException(nameof(stochasticSoilModel)); + } + if (surfaceLine == null) + { + throw new ArgumentNullException(nameof(surfaceLine)); + } + + Segment2D[] surfaceLineSegments = Math2D.ConvertLinePointsToLineSegments(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))).ToArray(); + return DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(stochasticSoilModel, surfaceLineSegments); + } + + private static bool DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(StochasticSoilModel stochasticSoilModel, Segment2D[] surfaceLineSegments) + { + IEnumerable soilProfileGeometrySegments = Math2D.ConvertLinePointsToLineSegments(stochasticSoilModel.Geometry); + return soilProfileGeometrySegments.Any(s => DoesSegmentIntersectWithSegmentArray(s, surfaceLineSegments)); + } + + private static bool DoesSegmentIntersectWithSegmentArray(Segment2D segment, Segment2D[] segmentArray) + { + // Consider intersections and overlaps similarly + return segmentArray.Any(sls => Math2D.GetIntersectionBetweenSegments(segment, sls).IntersectionType != Intersection2DType.DoesNotIntersect); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs =================================================================== diff -u -rfef932cbceb323536b66ee0278471cb77393a723 -r257b5b8c4e053ff875f75e0940a0f9d8775ef083 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs (.../PipingCalculationConfigurationHelper.cs) (revision fef932cbceb323536b66ee0278471cb77393a723) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PipingCalculationConfigurationHelper.cs (.../PipingCalculationConfigurationHelper.cs) (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -23,7 +23,6 @@ using System.Collections.Generic; using System.Linq; using Core.Common.Base.Data; -using Core.Common.Base.Geometry; using log4net; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Forms.Helpers; @@ -104,36 +103,11 @@ return Enumerable.Empty(); } - Segment2D[] surfaceLineSegments = Math2D.ConvertLinePointsToLineSegments(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))).ToArray(); - return availableSoilModels.Where(stochasticSoilModel => stochasticSoilModel.StochasticSoilProfiles.Any() && - DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(stochasticSoilModel, surfaceLineSegments)) + stochasticSoilModel.IntersectsWithSurfaceLineGeometry(surfaceLine)) .ToList(); } - /// - /// Indicates whether a stochastic soil model intersects with a surface line. - /// - /// The stochastic soil model used to match a surface line. - /// The surface line used to match a stochastic soil model. - /// true when the intersects with the ; - /// false otherwise. - /// Thrown when any input parameter is null. - public static bool DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(StochasticSoilModel stochasticSoilModel, RingtoetsPipingSurfaceLine surfaceLine) - { - if (stochasticSoilModel == null) - { - throw new ArgumentNullException(nameof(stochasticSoilModel)); - } - if (surfaceLine == null) - { - throw new ArgumentNullException(nameof(surfaceLine)); - } - Segment2D[] surfaceLineSegments = Math2D.ConvertLinePointsToLineSegments(surfaceLine.Points.Select(p => new Point2D(p.X, p.Y))).ToArray(); - - return DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(stochasticSoilModel, surfaceLineSegments); - } - private static CalculationGroup CreateCalculationGroup(RingtoetsPipingSurfaceLine surfaceLine, IEnumerable soilModels, GeneralPipingInput generalInput) { var calculationGroup = new CalculationGroup(surfaceLine.Name, true); @@ -166,17 +140,5 @@ Contribution = (RoundedDouble) stochasticSoilProfile.Probability }; } - - private static bool DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(StochasticSoilModel stochasticSoilModel, Segment2D[] surfaceLineSegments) - { - IEnumerable soilProfileGeometrySegments = Math2D.ConvertLinePointsToLineSegments(stochasticSoilModel.Geometry); - return soilProfileGeometrySegments.Any(s => DoesSegmentIntersectWithSegmentArray(s, surfaceLineSegments)); - } - - private static bool DoesSegmentIntersectWithSegmentArray(Segment2D segment, Segment2D[] segmentArray) - { - // Consider intersections and overlaps similarly - return segmentArray.Any(sls => Math2D.GetIntersectionBetweenSegments(segment, sls).IntersectionType != Intersection2DType.DoesNotIntersect); - } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingConfigurationImporter.cs =================================================================== diff -u -r225d7e99a0fa1f4c95c4d6babf29da7361bfdd75 -r257b5b8c4e053ff875f75e0940a0f9d8775ef083 --- Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingConfigurationImporter.cs (.../PipingConfigurationImporter.cs) (revision 225d7e99a0fa1f4c95c4d6babf29da7361bfdd75) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/Importers/PipingConfigurationImporter.cs (.../PipingConfigurationImporter.cs) (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -200,6 +200,15 @@ if (soilModel != null) { + if (pipingCalculation.InputParameters.SurfaceLine != null) + { + if (!soilModel.IntersectsWithSurfaceLineGeometry(pipingCalculation.InputParameters.SurfaceLine)) + { + log.Warn("Ondergrondmodel kruist niet met de profielschematisatie. Berekening overgeslagen."); + return; + } + } + pipingCalculation.InputParameters.StochasticSoilModel = soilModel; if (readCalculation.StochasticSoilProfile != null) Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj =================================================================== diff -u -r425a1030cf1f383e0a8f5cbd712c52c5cc2d3369 -r257b5b8c4e053ff875f75e0940a0f9d8775ef083 --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 425a1030cf1f383e0a8f5cbd712c52c5cc2d3369) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/Ringtoets.Piping.Data.Test.csproj (.../Ringtoets.Piping.Data.Test.csproj) (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -77,6 +77,7 @@ + Index: Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelExtensionsTest.cs =================================================================== diff -u --- Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelExtensionsTest.cs (revision 0) +++ Ringtoets/Piping/test/Ringtoets.Piping.Data.Test/StochasticSoilModelExtensionsTest.cs (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -0,0 +1,125 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Piping.Primitives; + +namespace Ringtoets.Piping.Data.Test +{ + [TestFixture] + public class StochasticSoilModelExtensionsTest + { + [Test] + public void IntersectsWithSurfaceLineGeometry_SoilModelNull_ThrowArgumentNullException() + { + // Setup + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + + StochasticSoilModel soilModel = null; + + // Call + TestDelegate test = () => soilModel.IntersectsWithSurfaceLineGeometry(surfaceLine); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("stochasticSoilModel", exception.ParamName); + } + + [Test] + public void IntersectsWithSurfaceLineGeometry_SurfaceLineNull_ThrowArgumentNullException() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + // Call + TestDelegate test = () => soilModel.IntersectsWithSurfaceLineGeometry(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("surfaceLine", exception.ParamName); + } + + [Test] + public void IntersectsWithSurfaceLineGeometry_SurfacelineIntersectingSoilModel_ReturnTrue() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) + }); + + // Call + bool intersecting = soilModel.IntersectsWithSurfaceLineGeometry(surfaceLine); + + // Assert + Assert.IsTrue(intersecting); + } + + [Test] + public void IntersectsWithSurfaceLineGeometry_SurfacelineNotIntersectingSoilModel_ReturnFalse() + { + // Setup + var soilModel = new StochasticSoilModel(1, "A", "B"); + soilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var surfaceLine = new RingtoetsPipingSurfaceLine(); + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 1.0, 0.0), + new Point3D(2.5, 1.0, 1.0), + new Point3D(5.0, 1.0, 0.0) + }); + + // Call + bool intersecting = soilModel.IntersectsWithSurfaceLineGeometry(surfaceLine); + + // Assert + Assert.IsFalse(intersecting); + } + } +} \ No newline at end of file Index: Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs =================================================================== diff -u -rfef932cbceb323536b66ee0278471cb77393a723 -r257b5b8c4e053ff875f75e0940a0f9d8775ef083 --- Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs (.../PipingCalculationConfigurationHelperTest.cs) (revision fef932cbceb323536b66ee0278471cb77393a723) +++ Ringtoets/Piping/test/Ringtoets.Piping.Forms.Test/PipingCalculationConfigurationHelperTest.cs (.../PipingCalculationConfigurationHelperTest.cs) (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -50,97 +50,6 @@ Assert.AreEqual(generalInput.WhitesDragCoefficient, calculationInput.InputParameters.WhitesDragCoefficient); } - [Test] - public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SoilModelNull_ThrowArgumentNullException() - { - // Setup - var surfaceLine = new RingtoetsPipingSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - new Point3D(3.0, 5.0, 0.0), - new Point3D(3.0, 0.0, 1.0), - new Point3D(3.0, -5.0, 0.0) - }); - - // Call - TestDelegate test = () => PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(null, surfaceLine); - - // Assert - var exception = Assert.Throws(test); - Assert.AreEqual("stochasticSoilModel", exception.ParamName); - } - - [Test] - public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SurfaceLineNull_ThrowArgumentNullException() - { - // Setup - var soilModel = new StochasticSoilModel(1, "A", "B"); - soilModel.Geometry.AddRange(new[] - { - new Point2D(1.0, 0.0), - new Point2D(5.0, 0.0) - }); - - // Call - TestDelegate test = () => PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(soilModel, null); - - // Assert - var exception = Assert.Throws(test); - Assert.AreEqual("surfaceLine", exception.ParamName); - } - - [Test] - public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SurfacelineIntersectingSoilModel_ReturnTrue() - { - // Setup - var soilModel = new StochasticSoilModel(1, "A", "B"); - soilModel.Geometry.AddRange(new[] - { - new Point2D(1.0, 0.0), - new Point2D(5.0, 0.0) - }); - - var surfaceLine = new RingtoetsPipingSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - new Point3D(3.0, 5.0, 0.0), - new Point3D(3.0, 0.0, 1.0), - new Point3D(3.0, -5.0, 0.0) - }); - - // Call - bool intersecting = PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(soilModel, surfaceLine); - - // Assert - Assert.IsTrue(intersecting); - } - - [Test] - public void DoesSoilModelGeometryIntersectWithSurfaceLineGeometry_SurfacelineNotIntersectingSoilModel_ReturnFalse() - { - // Setup - var soilModel = new StochasticSoilModel(1, "A", "B"); - soilModel.Geometry.AddRange(new[] - { - new Point2D(1.0, 0.0), - new Point2D(5.0, 0.0) - }); - - var surfaceLine = new RingtoetsPipingSurfaceLine(); - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 1.0, 0.0), - new Point3D(2.5, 1.0, 1.0), - new Point3D(5.0, 1.0, 0.0) - }); - - // Call - bool intersecting = PipingCalculationConfigurationHelper.DoesSoilModelGeometryIntersectWithSurfaceLineGeometry(soilModel, surfaceLine); - - // Assert - Assert.IsFalse(intersecting); - } - #region GetPipingSoilProfilesForSurfaceLine [Test] Index: Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingConfigurationImporterTest.cs =================================================================== diff -u -r225d7e99a0fa1f4c95c4d6babf29da7361bfdd75 -r257b5b8c4e053ff875f75e0940a0f9d8775ef083 --- Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingConfigurationImporterTest.cs (.../PipingConfigurationImporterTest.cs) (revision 225d7e99a0fa1f4c95c4d6babf29da7361bfdd75) +++ Ringtoets/Piping/test/Ringtoets.Piping.IO.Test/Importers/PipingConfigurationImporterTest.cs (.../PipingConfigurationImporterTest.cs) (revision 257b5b8c4e053ff875f75e0940a0f9d8775ef083) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.IO; using System.Linq; using Core.Common.Base.Geometry; @@ -30,7 +29,6 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Piping.Data; -using Ringtoets.Piping.Integration.TestUtils; using Ringtoets.Piping.IO.Importers; using Ringtoets.Piping.Primitives; @@ -288,6 +286,59 @@ } [Test] + public void Import_StochasticSoilModelNotIntersectingWithSurfaceLine_LogMessageAndContinueImport() + { + // Setup + string filePath = Path.Combine(path, "validConfigurationFullCalculationContainingHydraulicBoundaryLocation.xml"); + + var calculationGroup = new CalculationGroup(); + var surfaceLine = new RingtoetsPipingSurfaceLine + { + Name = "Profielschematisatie" + }; + surfaceLine.SetGeometry(new[] + { + new Point3D(0.0, 1.0, 0.0), + new Point3D(2.5, 1.0, 1.0), + new Point3D(5.0, 1.0, 0.0) + }); + var stochasticSoilModel = new StochasticSoilModel(1, "Ondergrondmodel", "Segment"); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); + + var pipingFailureMechanism = new PipingFailureMechanism(); + pipingFailureMechanism.SurfaceLines.AddRange(new[] + { + surfaceLine + }, "path"); + pipingFailureMechanism.StochasticSoilModels.AddRange(new[] + { + stochasticSoilModel + }, "path"); + + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "HRlocatie", 10, 20); + var importer = new PipingConfigurationImporter(filePath, + calculationGroup, + new[] + { + hydraulicBoundaryLocation + }, + pipingFailureMechanism); + + // Call + bool succesful = false; + Action call = () => succesful = importer.Import(); + + // Assert + TestHelper.AssertLogMessageIsGenerated(call, "Ondergrondmodel kruist niet met de profielschematisatie. Berekening overgeslagen.", 1); + Assert.IsTrue(succesful); + CollectionAssert.IsEmpty(calculationGroup.Children); + } + + [Test] public void Import_StochastichSoilProfileInvalid_LogMessageAndContinueImport() { // Setup @@ -300,10 +351,16 @@ }; surfaceLine.SetGeometry(new[] { - new Point3D(3.5, 2.3, 8.0), - new Point3D(6.9, 2.0, 2.0) + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) }); var stochasticSoilModel = new StochasticSoilModel(1, "Ondergrondmodel", "Segment"); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); var pipingFailureMechanism = new PipingFailureMechanism(); pipingFailureMechanism.SurfaceLines.AddRange(new[] @@ -349,8 +406,9 @@ }; surfaceLine.SetGeometry(new[] { - new Point3D(3.5, 2.3, 8.0), - new Point3D(6.9, 2.0, 2.0) + new Point3D(3.0, 5.0, 0.0), + new Point3D(3.0, 0.0, 1.0), + new Point3D(3.0, -5.0, 0.0) }); var stochasticSoilProfile = new StochasticSoilProfile(0, SoilProfileType.SoilProfile1D, 1) { @@ -362,6 +420,11 @@ var stochasticSoilModel = new StochasticSoilModel(1, "Ondergrondmodel", "Segment"); stochasticSoilModel.StochasticSoilProfiles.Add(stochasticSoilProfile); + stochasticSoilModel.Geometry.AddRange(new[] + { + new Point2D(1.0, 0.0), + new Point2D(5.0, 0.0) + }); var pipingFailureMechanism = new PipingFailureMechanism(); pipingFailureMechanism.SurfaceLines.AddRange(new[]