// Copyright (C) Stichting Deltares 2021. 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.Linq; using Deltares.Dam.Data; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using NUnit.Framework; using Segment = Deltares.Dam.Data.Segment; namespace Deltares.Dam.Tests { [TestFixture] public class WaterBoardPostProcessRelativeProfilesTest { private const double CTolerance = 0.0001; 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 WaterBoard CreateWaterBoard(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 }); var 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); var waterBoard = new WaterBoard(); waterBoard.Segments.Add(segment); waterBoard.Dikes.Add(dike); return waterBoard; } public void PostProcessWaterBoard(double offset) { using (WaterBoard waterBoard = CreateWaterBoard(offset)) { WaterBoardPostProcessRelativeProfiles.CreateAbsoluteProfiles(waterBoard, CharacteristicPointType.DikeToeAtPolder); // Is location soil profile moved var soilProfile1DLocation = waterBoard.Dikes[0].Locations[0].Segment.SoilProfileProbabilities[0].SoilProfile; AssertSoilProfile1D(offset, soilProfile1DLocation); // Is moved dike soil profile present in dike.SoilProfileList var soilProfile1DDike = waterBoard.Dikes[0].SoilProfiles.FirstOrDefault(p => p.Name.Equals(soilProfile1DLocation.Name)); AssertSoilProfile1D(offset, soilProfile1DDike); } } private static void AssertSoilProfile1D(double offset, SoilProfile1D soilProfile1D) { Assert.AreEqual(1.0 + offset, soilProfile1D.TopLevel, CTolerance); Assert.AreEqual(-1.0 + offset, soilProfile1D.Layers[1].TopLevel, CTolerance); Assert.AreEqual(-10.0 + offset, soilProfile1D.BottomLevel, CTolerance); } [Test] public void CanPostProcessWaterBoardNoMove() { PostProcessWaterBoard(0.0); } [Test] public void CanPostProcessWaterBoardMoveDown() { PostProcessWaterBoard(1.0); } [Test] public void CanPostProcessWaterBoardMoveDownMuch() { PostProcessWaterBoard(20.0); } [Test] public void CanPostProcessWaterBoardMoveUp() { PostProcessWaterBoard(-1.0); } [Test] public void CanPostProcessWaterBoardMoveUpMuch() { PostProcessWaterBoard(-20.0); } } }