// 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.Globalization; using System.IO; using System.Linq; using System.Threading; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.GeometryExport; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Interface; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.IntegrationTests.IntegrationTests; [TestFixture] public class IssuesTests { private const string tutorialStability2D = @"TestFiles\InputTutorialStability2D.xml"; [Test] [TestCase("DWP_1", 0,19, 81, 63, 35,1.248)] [TestCase("DWP_2", 1,12, 72, 61, 38,1.398)] [TestCase("DWP_6", 5, 15,79, 65, 45, 1.503)] [TestCase("DWP_7", 6,9, 65, 57, 37, 1.264)] [TestCase("DWP_8", 7,27, 117, 91, 46, 0.989)] [TestCase("DWP_16", 15,26, 99, 74, 39, 0.849)] [TestCase("DWP_20", 19,24, 102, 79, 46, 1.523)] public void TestGeometryAndResultForIssueWithDwpsFromTutorial(string location, int segmentIndex, int surfaceCount, int curveCount, int pointCount, int surfaceLinePointCount, double safetyFactor) { string inputString = File.ReadAllText(tutorialStability2D); string[] locations = [location]; inputString = XmlAdapter.SelectLocations(inputString, locations); var outputName = "OutputFor" + location + ".xml"; var engineInterface = new EngineInterface(inputString); //GeometryData geometry = engineInterface.DamProjectData.Segments[segmentIndex].SoilProfileProbabilities[0].SoilProfile2D.Geometry; SurfaceLine2 surfaceLine = engineInterface.DamProjectData.Dike.Locations[0].SurfaceLine; //GeometryExporter.ExportToFile(geometry, GeometryExporter.VisualizationFolder + location +"GeometryStart.txt"); //GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + // GeometryExporter.ExportJasonFile, geometry, surfaceLine.Geometry); string soilName = engineInterface.DamProjectData.Dike.Locations[0].DikeEmbankmentMaterial; Soil soil = engineInterface.DamProjectData.Dike.SoilList.GetSoilByName(soilName); // To be able to check the geometry, create it here. SoilProfile2D soilProfile2D = SoilProfile2DSurfaceLineHelper.CombineSurfaceLineWithSoilProfile2D(surfaceLine.Geometry, engineInterface.DamProjectData.Segments[segmentIndex].SoilProfileProbabilities[0].SoilProfile2D, soil); // For debugging purposes //geometry = soilProfile2D.Geometry; //GeometryExporter.ExportToFile(geometry, GeometryExporter.VisualizationFolder + location + "GeometryEnd.txt"); //GeometryExporter.ExportWithSurfaceLineToJsonFile(GeometryExporter.VisualizationFolder + // GeometryExporter.ExportJasonFile, geometry, surfaceLine.Geometry); Assert.Multiple(() => { Assert.That(soilProfile2D.Geometry.Surfaces, Has.Count.EqualTo(surfaceCount)); Assert.That(soilProfile2D.Geometry.Curves, Has.Count.EqualTo(curveCount)); Assert.That(soilProfile2D.Geometry.Points, Has.Count.EqualTo(pointCount)); Assert.That(soilProfile2D.Geometry.SurfaceLine.CalcPoints, Has.Count.EqualTo(surfaceLinePointCount)); }); GeneralHelper.RunAfterInputValidation(engineInterface, true, outputName); int errorCount = GeneralHelper.DetermineNumberOfCalculationErrors(engineInterface.DamProjectData.CalculationMessages); Assert.Multiple(() => { Assert.That(errorCount, Is.EqualTo(0), "There should be no errors during the calculation."); Assert.That(engineInterface.DamProjectData.DesignCalculations, Has.Count.EqualTo(1), "There should be one design calculation."); Assert.That(engineInterface.DamProjectData.DesignCalculations[0].SafetyFactor, Is.EqualTo(safetyFactor).Within(0.001), "The safety factor is incorrect."); }); } }