// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI 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.Linq; using Deltares.Dam.Data; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class DikePostProcessRelativeProfilesTest { private const double cTolerance = 0.0001; [Test] public void CanPostProcessDikeNoMove() { PostProcessDike(0.0); } [Test] public void CanPostProcessDikeMoveDown() { PostProcessDike(1.0); } [Test] public void CanPostProcessDikeMoveDownMuch() { PostProcessDike(20.0); } [Test] public void CanPostProcessDikeMoveUp() { PostProcessDike(-1.0); } [Test] public void CanPostProcessDikeMoveUpMuch() { PostProcessDike(-20.0); } private static SurfaceLine2 CreateSimpleSurfaceLine(double offset) { var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new LocalizedGeometryPointString() }; surfaceLine.EnsurePointOfType(0, 2 + offset, CharacteristicPointType.DikeToeAtRiver); surfaceLine.EnsurePointOfType(1, 2 + offset, CharacteristicPointType.DikeTopAtRiver); surfaceLine.EnsurePointOfType(2, 2 + offset, CharacteristicPointType.DikeTopAtPolder); surfaceLine.EnsurePointOfType(3, 1 + offset, CharacteristicPointType.DikeToeAtPolder); surfaceLine.EnsurePointOfType(100, 1 + offset, CharacteristicPointType.SurfaceLevelInside); return surfaceLine; } private static Dike CreateDike(double offset) { var segment = new Segment(); var soilProfile1D = new SoilProfile1D(); soilProfile1D.Layers.Add(new SoilLayer1D { TopLevel = 1.0 }); soilProfile1D.Layers.Add(new SoilLayer1D { TopLevel = -1.0 }); soilProfile1D.BottomLevel = -10; segment.SoilProfileProbabilities.Add(new SoilGeometryProbability { SoilProfile = soilProfile1D }); SurfaceLine2 simpleSurfaceLine = CreateSimpleSurfaceLine(offset); var location = new Location { Name = "location 1" }; location.Segment = segment; location.SurfaceLine2 = simpleSurfaceLine; var dike = new Dike { Name = "Dike" }; dike.Locations.Add(location); dike.SurfaceLines2.Add(simpleSurfaceLine); dike.SoilProfiles.Add(soilProfile1D); dike.Segments.Add(segment); return dike; } private static void PostProcessDike(double offset) { using (Dike dike = CreateDike(offset)) { DikePostProcessRelativeProfiles.CreateAbsoluteProfiles(dike, CharacteristicPointType.DikeToeAtPolder); // Is location soil profile moved SoilProfile1D soilProfile1DLocation = dike.Locations[0].Segment.SoilProfileProbabilities[0].SoilProfile; AssertSoilProfile1D(offset, soilProfile1DLocation); // Is moved dike soil profile present in dike.SoilProfileList SoilProfile1D soilProfile1DDike = dike.SoilProfiles.FirstOrDefault(p => p.Name.Equals(soilProfile1DLocation.Name)); AssertSoilProfile1D(offset, soilProfile1DDike); } } private static void AssertSoilProfile1D(double offset, SoilProfile1D soilProfile1D) { // If there is no move, than there is no added layer if (Math.Abs(offset) < cTolerance) { Assert.Multiple(() => { Assert.That(soilProfile1D.TopLevel, Is.EqualTo(1.0 + offset).Within(cTolerance)); Assert.That(soilProfile1D.Layers[1].TopLevel, Is.EqualTo(-1.0 + offset).Within(cTolerance)); Assert.That(soilProfile1D.BottomLevel, Is.EqualTo(-10.0 + offset).Within(cTolerance)); }); } else { Assert.Multiple(() => { // If there is a move, than there is one added (top) layer Assert.That(soilProfile1D.TopLevel, Is.EqualTo(2.0 + offset).Within(cTolerance)); Assert.That(soilProfile1D.Layers[2].TopLevel, Is.EqualTo(-1.0 + offset).Within(cTolerance)); Assert.That(soilProfile1D.BottomLevel, Is.EqualTo(-10.0 + offset).Within(cTolerance)); }); } } } }