// Copyright (C) Stichting Deltares 2024. 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.Collections.Generic; using System.Linq; using Components.Persistence.Stability.Version2.Data; using Deltares.Geometry; using Deltares.Geotechnics.Soils; using Deltares.Standard.Validation; using NUnit.Framework; namespace Deltares.Dam.StixFileReader.Tests; [TestFixture] public class SoilProfile2DDataModelTest { [Test] public void WhenDataModelWithMultipleScenarioAndStagesIsCreated_ThenGeometryFromLastScenarioAndStageIsRetrieved() { PersistableDataModel dataModel = PersistableDataModelFactory.CreateSimpleDataModelWithMultipleScenarioAndStages(); SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel, 0.0); Assert.Multiple(() => { Assert.That(soilProfile2D.Geometry.MinGeometryPointsX, Is.EqualTo(-500)); Assert.That(soilProfile2D.Geometry.MaxGeometryPointsX, Is.EqualTo(500)); Assert.That(soilProfile2D.Geometry.MinGeometryPointsZ, Is.EqualTo(-100)); Assert.That(soilProfile2D.Geometry.MaxGeometryPointsZ, Is.EqualTo(100)); Assert.That(soilProfile2D.Geometry.Left, Is.EqualTo(-500)); Assert.That(soilProfile2D.Geometry.Right, Is.EqualTo(500)); Assert.That(soilProfile2D.Geometry.Bottom, Is.EqualTo(-100)); }); } [Test] [TestCase(0.0)] [TestCase(5.45)] [TestCase(-15.225)] public void WhenDataModelWithMultipleLayersIsCreated_ThenSoilProfile2DIsAsExpected(double shift) { PersistableDataModel dataModel = PersistableDataModelFactory.CreateSimpleDataModelWithMultipleLayers(); SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel, shift); IList points = soilProfile2D.Geometry.Points; Assert.Multiple(() => { Assert.That(points.ElementAt(0).LocationEquals(new GeometryPoint(12 + shift, 0, -5)), Is.True); Assert.That(points.ElementAt(1).LocationEquals(new GeometryPoint(12 + shift, 0, 5)), Is.True); Assert.That(points.ElementAt(2).LocationEquals(new GeometryPoint(15 + shift, 0, 5)), Is.True); Assert.That(points.ElementAt(3).LocationEquals(new GeometryPoint(15 + shift, 0, -5)), Is.True); Assert.That(points.ElementAt(4).LocationEquals(new GeometryPoint(10 + shift, 0, -10)), Is.True); Assert.That(points.ElementAt(5).LocationEquals(new GeometryPoint(10 + shift, 0, 10)), Is.True); Assert.That(points.ElementAt(6).LocationEquals(new GeometryPoint(20 + shift, 0, 10)), Is.True); Assert.That(points.ElementAt(7).LocationEquals(new GeometryPoint(20 + shift, 0, -10)), Is.True); Assert.That(points.ElementAt(8).LocationEquals(new GeometryPoint(18 + shift, 0, 5)), Is.True); Assert.That(points.ElementAt(9).LocationEquals(new GeometryPoint(18 + shift, 0, -5)), Is.True); }); Assert.That(soilProfile2D.Geometry.Surfaces.Count, Is.EqualTo(3)); List curves = soilProfile2D.Surfaces.ElementAt(0).GeometrySurface.OuterLoop.CurveList; Assert.Multiple(() => { Assert.That(curves.ElementAt(0).LocationEquals(new GeometryCurve(new GeometryPoint(12 + shift, 0, -5), new GeometryPoint(12 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(1).LocationEquals(new GeometryCurve(new GeometryPoint(12 + shift, 0, 5), new GeometryPoint(15 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(2).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, 5), new GeometryPoint(15 + shift, 0, -5))), Is.True); Assert.That(curves.ElementAt(3).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, -5), new GeometryPoint(12 + shift, 0, -5))), Is.True); }); curves = soilProfile2D.Surfaces.ElementAt(1).GeometrySurface.OuterLoop.CurveList; Assert.Multiple(() => { Assert.That(curves.ElementAt(0).LocationEquals(new GeometryCurve(new GeometryPoint(10 + shift, 0, -10), new GeometryPoint(10 + shift, 0, 10))), Is.True); Assert.That(curves.ElementAt(1).LocationEquals(new GeometryCurve(new GeometryPoint(10 + shift, 0, 10), new GeometryPoint(20 + shift, 0, 10))), Is.True); Assert.That(curves.ElementAt(2).LocationEquals(new GeometryCurve(new GeometryPoint(20 + shift, 0, 10), new GeometryPoint(20 + shift, 0, -10))), Is.True); Assert.That(curves.ElementAt(3).LocationEquals(new GeometryCurve(new GeometryPoint(20 + shift, 0, -10), new GeometryPoint(10 + shift, 0, -10))), Is.True); }); curves = soilProfile2D.Surfaces.ElementAt(2).GeometrySurface.OuterLoop.CurveList; Assert.Multiple(() => { Assert.That(curves.ElementAt(0).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, 5), new GeometryPoint(18 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(1).LocationEquals(new GeometryCurve(new GeometryPoint(18 + shift, 0, 5), new GeometryPoint(18 + shift, 0, -5))), Is.True); Assert.That(curves.ElementAt(2).LocationEquals(new GeometryCurve(new GeometryPoint(18 + shift, 0, -5), new GeometryPoint(15 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(3).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, 5), new GeometryPoint(15 + shift, 0, 5))), Is.True); }); Assert.That(soilProfile2D.Geometry.SurfaceLine.Points.ElementAt(0).LocationEquals(new GeometryPoint(10 + shift, 0, 10)), Is.True); Assert.That(soilProfile2D.Geometry.SurfaceLine.Points.ElementAt(1).LocationEquals(new GeometryPoint(20 + shift, 0, 10)), Is.True); curves = soilProfile2D.Geometry.Curves; Assert.Multiple(() => { Assert.That(curves.ElementAt(0).LocationEquals(new GeometryCurve(new GeometryPoint(12 + shift, 0, -5), new GeometryPoint(12 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(1).LocationEquals(new GeometryCurve(new GeometryPoint(12 + shift, 0, 5), new GeometryPoint(15 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(2).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, 5), new GeometryPoint(15 + shift, 0, -5))), Is.True); Assert.That(curves.ElementAt(3).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, -5), new GeometryPoint(12 + shift, 0, -5))), Is.True); Assert.That(curves.ElementAt(4).LocationEquals(new GeometryCurve(new GeometryPoint(10 + shift, 0, -10), new GeometryPoint(10 + shift, 0, 10))), Is.True); Assert.That(curves.ElementAt(5).LocationEquals(new GeometryCurve(new GeometryPoint(10 + shift, 0, 10), new GeometryPoint(20 + shift, 0, 10))), Is.True); Assert.That(curves.ElementAt(6).LocationEquals(new GeometryCurve(new GeometryPoint(20 + shift, 0, 10), new GeometryPoint(20 + shift, 0, -10))), Is.True); Assert.That(curves.ElementAt(7).LocationEquals(new GeometryCurve(new GeometryPoint(20 + shift, 0, -10), new GeometryPoint(10 + shift, 0, -10))), Is.True); Assert.That(curves.ElementAt(8).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, 5), new GeometryPoint(18 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(9).LocationEquals(new GeometryCurve(new GeometryPoint(18 + shift, 0, 5), new GeometryPoint(18 + shift, 0, -5))), Is.True); Assert.That(curves.ElementAt(10).LocationEquals(new GeometryCurve(new GeometryPoint(18 + shift, 0, -5), new GeometryPoint(15 + shift, 0, 5))), Is.True); Assert.That(curves.ElementAt(11).LocationEquals(new GeometryCurve(new GeometryPoint(15 + shift, 0, 5), new GeometryPoint(15 + shift, 0, 5))), Is.True); }); ValidationResult[] validationResults = soilProfile2D.Surfaces[0].ValidateLayer(); Assert.That(validationResults, Has.Length.EqualTo(0)); validationResults = soilProfile2D.Surfaces[1].ValidateLayer(); Assert.That(validationResults, Has.Length.EqualTo(0)); validationResults = soilProfile2D.Surfaces[2].ValidateLayer(); Assert.That(validationResults, Has.Length.EqualTo(0)); validationResults = soilProfile2D.Geometry.ValidateGeometry(); Assert.That(validationResults, Has.Length.EqualTo(0)); soilProfile2D.Geometry.RegenerateGeometry(); validationResults = soilProfile2D.Geometry.ValidateGeometry(); Assert.That(validationResults, Has.Length.EqualTo(0)); } [Test] public void WhenDataModelWithInnerLoopsIsCreated_ThenSoilProfile2DIsAsExpected() { const double shift = 0; PersistableDataModel dataModel = PersistableDataModelFactory.CreateSimpleDataModelWithInnerLoops(); SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel, 0); IList points = soilProfile2D.Geometry.Points; Assert.That(points, Has.Count.EqualTo(16)); Assert.Multiple(() => { Assert.That(points.ElementAt(0).LocationEquals(new GeometryPoint(10, 0, -5)), Is.True); Assert.That(points.ElementAt(1).LocationEquals(new GeometryPoint(10, 0, 5)), Is.True); Assert.That(points.ElementAt(2).LocationEquals(new GeometryPoint(60, 0, 5)), Is.True); Assert.That(points.ElementAt(3).LocationEquals(new GeometryPoint(60, 0, -5)), Is.True); Assert.That(points.ElementAt(4).LocationEquals(new GeometryPoint(20, 0, -4)), Is.True); Assert.That(points.ElementAt(5).LocationEquals(new GeometryPoint(20, 0, 4)), Is.True); Assert.That(points.ElementAt(6).LocationEquals(new GeometryPoint(30, 0, 4)), Is.True); Assert.That(points.ElementAt(7).LocationEquals(new GeometryPoint(30, 0, -4)), Is.True); Assert.That(points.ElementAt(8).LocationEquals(new GeometryPoint(40, 0, 4)), Is.True); Assert.That(points.ElementAt(9).LocationEquals(new GeometryPoint(40, 0, -4)), Is.True); Assert.That(points.ElementAt(10).LocationEquals(new GeometryPoint(50, 0, -4)), Is.True); Assert.That(points.ElementAt(11).LocationEquals(new GeometryPoint(50, 0, 4)), Is.True); Assert.That(points.ElementAt(12).LocationEquals(new GeometryPoint(21, 0, 3)), Is.True); Assert.That(points.ElementAt(13).LocationEquals(new GeometryPoint(21, 0, -3)), Is.True); Assert.That(points.ElementAt(14).LocationEquals(new GeometryPoint(29, 0, -3)), Is.True); Assert.That(points.ElementAt(15).LocationEquals(new GeometryPoint(29, 0, 3)), Is.True); }); Assert.That(soilProfile2D.Geometry.Surfaces, Has.Count.EqualTo(4)); Assert.Multiple(() => { Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(0).OuterLoop.CurveList, Has.Count.EqualTo(4)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(0).InnerLoops, Has.Count.EqualTo(2)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(1).OuterLoop.CurveList, Has.Count.EqualTo(4)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(1).InnerLoops, Has.Count.EqualTo(1)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(2).OuterLoop.CurveList, Has.Count.EqualTo(4)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(2).InnerLoops, Has.Count.EqualTo(0)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(3).OuterLoop.CurveList, Has.Count.EqualTo(4)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(3).InnerLoops, Has.Count.EqualTo(0)); }); Assert.Multiple(() => { Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(0).InnerLoops.ElementAt(0).CurveList, Has.Count.EqualTo(4)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(0).InnerLoops.ElementAt(1).CurveList, Has.Count.EqualTo(4)); Assert.That(soilProfile2D.Geometry.Surfaces.ElementAt(1).InnerLoops.ElementAt(0).CurveList, Has.Count.EqualTo(4)); }); } }