// Copyright (C) Stichting Deltares 2019. 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; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard; using Deltares.DamEngine.TestHelpers.Factories; using NUnit.Framework; namespace Deltares.DamEngine.Data.Tests.Geotechnics { [TestFixture] public class SoilSurfaceProfileTests { [Test] public void TestCreate2DProfileWithSimpleSurfaceLineAboveProfile() { // Create a 1D profiles with toplayer at -2 var prof1D = CreateTwoLayerProfile(-2); // surfaceLine has 7 points, varies in height from -1 to 5 m var surfaceLine = FactoryForSurfaceLines.CreateSimpleSurfaceLineForExitPointTest(); // Create profile var soilSurfaceProfile = new SoilSurfaceProfile { SoilProfile = prof1D, SurfaceLine2 = surfaceLine, DikeEmbankmentMaterial = new Soil { Name = "Dike material" } }; var profile2D = soilSurfaceProfile.ConvertToSoilProfile2D(); Assert.AreEqual(13, profile2D.Geometry.Points.Count); Assert.AreEqual(15, profile2D.Geometry.Curves.Count); Assert.AreEqual(3, profile2D.Surfaces.Count); } [Test] public void ConvertToSoilProfile2D_WithSurfaceLineAboveSoilLayers_SetsCorrectSurfacesAndGeometry() { // Setup const string bottomLayerName = "BottomLayer"; const string middleLayerName = "MiddleLayer"; const string topLayerName = "TopLayer"; var profile = new SoilProfile1D { BottomLevel = -10 }; profile.Layers.Add(CreateSoilLayer(-5, bottomLayerName)); profile.Layers.Add(CreateSoilLayer(-2, middleLayerName)); SurfaceLine2 surfaceLine = CreateSurfaceLine(new[] { new GeometryPoint(0, 0), new GeometryPoint(5, 10), new GeometryPoint(10, 10) }); var soilSurfaceProfile = new SoilSurfaceProfile { SoilProfile = profile, SurfaceLine2 = surfaceLine, DikeEmbankmentMaterial = new Soil { Name = topLayerName } }; // Call soilSurfaceProfile.ConvertToSoilProfile2D(); // Assert var soilLayer2Ds = soilSurfaceProfile.Surfaces; Assert.That(soilLayer2Ds, Has.Count.EqualTo(3)); GeometryLoop topSurface = soilLayer2Ds.Single(l => string.Equals(l.Name, topLayerName)).GeometrySurface.OuterLoop; AssertGeometry(new [] { new GeometryCurve(new Point2D(10, -2), new Point2D(0, -2)), new GeometryCurve(new Point2D(0, -2), new Point2D(0, 0)), new GeometryCurve(new Point2D(0, 0), new Point2D(5, 10)), new GeometryCurve(new Point2D(5, 10), new Point2D(10, 10)), new GeometryCurve(new Point2D(10, 10), new Point2D(10, -2)), }, topSurface.CurveList); GeometryLoop middleSurface = soilLayer2Ds.Single(l => string.Equals(l.Name, middleLayerName)).GeometrySurface.OuterLoop; AssertGeometry(new[] { new GeometryCurve(new Point2D(0, -2), new Point2D(10, -2)), new GeometryCurve(new Point2D(10, -2), new Point2D(10, -5)), new GeometryCurve(new Point2D(10, -5), new Point2D(0, -5)), new GeometryCurve(new Point2D(0, -5), new Point2D(0, -2)) }, middleSurface.CurveList); GeometryLoop bottomSurface = soilLayer2Ds.Single(l => string.Equals(l.Name, bottomLayerName)).GeometrySurface.OuterLoop; AssertGeometry(new[] { new GeometryCurve(new Point2D(0, -5), new Point2D(10, -5)), new GeometryCurve(new Point2D(10, -5), new Point2D(10, -10)), new GeometryCurve(new Point2D(10, -10), new Point2D(0, -10)), new GeometryCurve(new Point2D(0, -10), new Point2D(0, -5)) }, bottomSurface.CurveList); } private static void AssertGeometry(IEnumerable expectedCurves, IEnumerable actualCurves) { int nrOfExpectedCurves = expectedCurves.Count(); Assert.That(actualCurves.Count(), Is.EqualTo(nrOfExpectedCurves)); for (int i = 0; i < nrOfExpectedCurves; i++) { GeometryCurve expectedCurve = expectedCurves.ElementAt(i); GeometryCurve actualCurve = actualCurves.ElementAt(i); Assert.That(actualCurve.LocationEquals(expectedCurve), Is.True); } } private static SoilLayer1D CreateSoilLayer(double topLevel, string soilName) { return new SoilLayer1D { TopLevel = topLevel, Soil = new Soil(soilName) }; } private static SurfaceLine2 CreateSurfaceLine(IEnumerable coordinates) { var surfaceLine = new SurfaceLine2(); surfaceLine.Geometry.Points.AddRange(coordinates); surfaceLine.Geometry.SyncCalcPoints(); return surfaceLine; } private static SoilProfile1D CreateTwoLayerProfile(double offset = 0) { var soilProfile = new SoilProfile1D(); var layer = new SoilLayer1D(); layer.TopLevel = 0.0 + offset; layer.Soil = new Soil("HW-OBO", 12.0, 10.0); layer.Soil.DryUnitWeight = 0.01; layer.IsAquifer = false; layer.WaterpressureInterpolationModel = WaterpressureInterpolationModel.Automatic; soilProfile.Layers.Add(layer); layer = new SoilLayer1D(); layer.TopLevel = -5.0 + offset; layer.Soil = new Soil("Alg-zand (0-30)", 22.0, 20.0); layer.Soil.DryUnitWeight = 0.01; layer.IsAquifer = true; layer.WaterpressureInterpolationModel = WaterpressureInterpolationModel.Hydrostatic; soilProfile.Layers.Add(layer); soilProfile.BottomLevel = -10.0 + offset; return soilProfile; } } }