// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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.Linq; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.TestHelpers.Factories; using Deltares.DamEngine.TestHelpers.Geometry; using NUnit.Framework; using Soil = Deltares.DamEngine.Data.Geotechnics.Soil; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityCommon; [TestFixture] public class MacroStabilityCommonHelperTests { // For debugging purposes private const string visualizationFolder = @"D:\src\dam\DamTools\GeometryVisualizer\"; private readonly double cTolerance = 0.001; [Test] public void GivenSoilGeometryProbabilityWithSoilProfile1DAndSurfaceLineWhenCombiningThenSoilProfile2DIsCreated() { SoilGeometryProbability soilGeometryProbability = FactoryForSoilGeometryProbabilities.CreateSoilGeometryProbabilityWithSoilProfile1D(); SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateSurfaceLineWithDikeAndDitch(); MacroStabilityCommonHelper.CombineSoilProfileWithSurfaceLine(soilGeometryProbability, surfaceLine, new Soil()); GeometryData geometry = soilGeometryProbability.SoilProfile2D.Geometry; // For debugging purposes // GeometryExporter.ExportToFile(geometry, visualizationFolder + "Geometry.txt"); // GeometryExporter.ExportToJsonFile(geometry, visualizationFolder + "Geometry.json"); Assert.Multiple(() => { Assert.That(soilGeometryProbability.SoilProfileType, Is.EqualTo(SoilProfileType.ProfileType2D)); Assert.That(geometry.Surfaces, Has.Count.EqualTo(1)); Assert.That(geometry.Left, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.Right, Is.EqualTo(75.0).Within(cTolerance)); Assert.That(geometry.Bottom, Is.EqualTo(-20.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.First().X, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.First().Z, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.Last().X, Is.EqualTo(75.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.Last().Z, Is.EqualTo(0.0).Within(cTolerance)); }); } [Test] public void GivenSoilGeometryProbabilityWithSoilProfile2DAndMatchingSurfaceLineWhenCombiningThenSoilProfile2DIsUnchanged() { SoilGeometryProbability soilGeometryProbability = CreateSoilGeometryProbabilityWithSoilProfile2DWithSurfaceLineDitchDike(); // Create the same surfaceline as is used for creating the SoilProfile2D in the SoilGeometryProbability SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateSurfaceLineWithDikeAndDitch(); // Now combine the soilGeometryProbability with the same SurfaceLine2 which should result in the same SoilProfile2D MacroStabilityCommonHelper.CombineSoilProfileWithSurfaceLine(soilGeometryProbability, surfaceLine, new Soil()); GeometryData geometry = soilGeometryProbability.SoilProfile2D.Geometry; // For debugging purposes // GeometryExporter.ExportToFile(geometry, visualizationFolder + "Geometry.txt"); // GeometryExporter.ExportToJsonFile(geometry, visualizationFolder + "Geometry.json"); Assert.Multiple(() => { Assert.That(soilGeometryProbability.SoilProfileType, Is.EqualTo(SoilProfileType.ProfileType2D)); Assert.That(geometry.Surfaces, Has.Count.EqualTo(1)); Assert.That(geometry.Left, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.Right, Is.EqualTo(75.0).Within(cTolerance)); Assert.That(geometry.Bottom, Is.EqualTo(-20.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.First().X, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.First().Z, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.Last().X, Is.EqualTo(75.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.Last().Z, Is.EqualTo(0.0).Within(cTolerance)); }); } [Test] public void GivenSoilGeometryProbabilityWithSoilProfile2DAndMatchingSurfaceLineShortOnLeftWhenCombiningThenSoilProfile2DIsCutOnTheLeft() { SoilGeometryProbability soilGeometryProbability = CreateSoilGeometryProbabilityWithSoilProfile2DWithSurfaceLineDitchDike(); // Create the same surfaceline as is used for creating the SoilProfile2D in the SoilGeometryProbability // But now the SurfaceLine2 is shorter on the left side (5.0 instead of 0.0) SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateSurfaceLineWithDikeAndDitch(); surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.SurfaceLevelOutside).X = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.SurfaceLevelOutside).X + 5.0; // Now combine the soilGeometryProbability with the same SurfaceLine2 which should result the SoilProfile2D // being cut to the left with 5.0 meters MacroStabilityCommonHelper.CombineSoilProfileWithSurfaceLine(soilGeometryProbability, surfaceLine, new Soil()); GeometryData geometry = soilGeometryProbability.SoilProfile2D.Geometry; // For debugging purposes // GeometryExporter.ExportToFile(geometry, visualizationFolder + "Geometry.txt"); // GeometryExporter.ExportToJsonFile(geometry, visualizationFolder + "Geometry.json"); Assert.Multiple(() => { Assert.That(soilGeometryProbability.SoilProfileType, Is.EqualTo(SoilProfileType.ProfileType2D)); Assert.That(geometry.Surfaces, Has.Count.EqualTo(1)); Assert.That(geometry.Left, Is.EqualTo(5.0).Within(cTolerance)); Assert.That(geometry.Right, Is.EqualTo(75.0).Within(cTolerance)); Assert.That(geometry.Bottom, Is.EqualTo(-20.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.First().X, Is.EqualTo(5.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.First().Z, Is.EqualTo(0.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.Last().X, Is.EqualTo(75.0).Within(cTolerance)); Assert.That(geometry.SurfaceLine.Points.Last().Z, Is.EqualTo(0.0).Within(cTolerance)); }); } private SoilGeometryProbability CreateSoilGeometryProbabilityWithSoilProfile2DWithSurfaceLineDitchDike() { SoilGeometryProbability soilGeometryProbability = FactoryForSoilGeometryProbabilities.CreateSoilGeometryProbabilityWithSoilProfile1D(); SurfaceLine2 surfaceLine = FactoryForSurfaceLines.CreateSurfaceLineWithDikeAndDitch(); MacroStabilityCommonHelper.CombineSoilProfileWithSurfaceLine(soilGeometryProbability, surfaceLine, new Soil()); return soilGeometryProbability; } }