// Copyright (C) Stichting Deltares 2025. 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.IO; using System.Linq; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon; using Deltares.DamEngine.Data.General; 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 { [Test] [TestCase("DWP_1", "SegDWP_1",19, 81, 63, 35, 1.245)] [TestCase("DWP_2", "SegDWP_2",12, 72, 61, 38, 1.398)] [TestCase("DWP_6", "SegDWP_6",15, 79, 65, 45, 1.503)] [TestCase("DWP_7", "SegDWP_7",9, 65, 57, 37, 1.264)] [TestCase("DWP_8", "SegDWP_8",27, 117, 91, 46, 1.020)] [TestCase("DWP_16", "SegDWP_16",26, 99, 74, 39, 0.713)] [TestCase("DWP_17", "SegDWP_17",18, 81, 64, 33, 1.256)] [TestCase("DWP_20", "SegDWP_20",25, 104, 80, 46, 1.523)] public void TestGeometryAndResultForIssueWithDwpsFromTutorial(string location, string segment, int surfaceCount, int curveCount, int pointCount, int surfaceLinePointCount, double safetyFactor) { const string calcDir = "TestGeometryAndResultForIssueWithDwpsFromTutorial"; const string tutorialStability2D = @"TestFiles\InputTutorialStability2D.xml"; TestGeometryAndResult(calcDir, tutorialStability2D, location, segment, surfaceCount, curveCount, pointCount, surfaceLinePointCount, safetyFactor); } [Test, Category(Categories.Slow)] [TestCase("PU0021_87074-1_DWP002", "PU0021_87074-1_DWP002",14, 188, 175, 111, 0.659)] [TestCase("PU0063_87074-1_DWP004", "PU0063_87074-1_DWP004",37, 296, 260, 181, 0.873)] [TestCase("PU0181_87074-1_DWP012", "PU0181_87074-1_DWP012",12, 180, 169, 112, 0.809)] [TestCase("PU0207_87074-1_DWP014", "PU0207_87074-1_DWP014",9, 148, 140, 110, 1.205)] public void TestGeometryAndResultForIssueMWDAM_3266(string location, string segment, int surfaceCount, int curveCount, int pointCount, int surfaceLinePointCount, double safetyFactor) { const string calcDir = "TestGeometryAndResultForIssueMWDAM_3266"; const string xmlInput = @"TestFiles\InputFileMWDAM-3266.xml"; TestGeometryAndResult(calcDir, xmlInput, location, segment, surfaceCount, curveCount, pointCount, surfaceLinePointCount, safetyFactor); } private static void TestGeometryAndResult(string calcDirectory, string xmlInput, string location, string segment, int surfaceCount, int curveCount, int pointCount, int surfaceLinePointCount, double safetyFactor) { if (Directory.Exists(calcDirectory)) { Directory.Delete(calcDirectory, true); // delete previous results } Directory.CreateDirectory(calcDirectory); string inputString = File.ReadAllText(xmlInput); string[] locations = [location]; inputString = XmlAdapter.SelectLocations(inputString, locations); inputString = XmlAdapter.ChangeValueInXml(inputString, "SearchMethod", "CalculationGrid"); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDirectory); // Current directory will be used string 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. SoilGeometryProbability soilProfile2DOriginal = engineInterface.DamProjectData.Segments.First(s => s.Name == segment).SoilProfileProbabilities[0]; SoilProfile2D soilProfile2D = MacroStabilityCommonHelper.CombineSoilProfileWithSurfaceLine(soilProfile2DOriginal, surfaceLine, 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.Points, 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."); }); } }