// Copyright (C) Stichting Deltares 2023. 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; using System.Collections.Generic; using System.IO; using Deltares.Dam.Data; using Deltares.Dam.Data.DamEngineIo; using Deltares.Dam.TestHelper; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using NUnit.Framework; namespace Deltares.Dam.BenchmarkTests; [TestFixture] public class DamCalculationBenchmarkTest { private const double cTolerance = 0.001; #region SupportingMethods #endregion SupportingMethods #region Uplift /// /// Compute project /// /// /// /// /// private static List ComputeStabilityInsideProject(string projectFilename, MStabModelType modelType, int expectedLocations, int maxCores = 1) { using (DamProjectData damProjectData = ProjectLoader.LoadProjectData(projectFilename)) { Assert.AreEqual(1, damProjectData.WaterBoard.Dikes.Count); Dike dike = damProjectData.WaterBoard.Dikes[0]; Assert.AreEqual(expectedLocations, dike.Locations.Count); // Specify calculation damProjectData.MaxCalculationCores = maxCores; damProjectData.DamProjectCalculationSpecification.CurrentSpecification.StabilityModelType = modelType; damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismeParamatersMStab .MStabParameters.GridPosition = MStabGridPosition.Right; damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismeParamatersMStab .MStabParameters.SearchMethod = MStabSearchMethod.Grid; damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType = FailureMechanismSystemType.StabilityInside; damProjectData.LocationJobs[0].Run = true; DamProjectCalculationSpecification.SelectedAnalysisType = AnalysisType.NoAdaption; Input input = FillXmlInputFromDamUi.CreateInput(damProjectData); string inputXml = DamXmlSerialization.SaveInputAsXmlString(input); var damEngineInterface = new EngineInterface(inputXml); string validationMessages = damEngineInterface.Validate(); if (string.IsNullOrEmpty(validationMessages)) { // only if validation is ok, then string outputXml = damEngineInterface.Run(); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputXml); FillDamUiFromXmlOutput.AddOutputToDamProjectData(damProjectData, output); } List allCalculationResults = damProjectData.DesignCalculations; return allCalculationResults; } } private void RemoveCalculationDirectoriesForProject(string aProjectName) { string folderName = aProjectName.Replace(".damx", ".Calc"); if (Directory.Exists(folderName)) { const bool recursive = true; Directory.Delete(folderName, recursive); } } /// /// Performs test BM04Opdijven01 situation without uplift 1D /// [Test] [Category("Slow")] public void BM04Opdrijven01SituatieZonderOpdrijven1D() { const string cFolderName = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\01 Situatie zonder opdrijven (1D)\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cFolderName); List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.UpliftVan, 1); Assert.IsTrue(allCalculationResults[0].IsUplift.Value); Assert.AreEqual(1.024077029, allCalculationResults[0].Pl3MinUplift.Value, cTolerance); Assert.AreEqual(49.1, allCalculationResults[0].Pl3LocalLocationXMinUplift.Value, cTolerance); } /// /// Performs test BM04Opdrijven02 situation where uplift occurs 1D /// [Test] [Category("Slow")] public void BM04Opdrijven02SituatieMetOpdrijven1D() { const string cFolderName = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\02 Situatie met opdrijven (1D)\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cFolderName); List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.UpliftVan, 1); Assert.IsTrue(allCalculationResults[0].IsUplift.Value); Assert.AreEqual(0.905914295, allCalculationResults[0].Pl3MinUplift.Value, cTolerance); Assert.AreEqual(-1.289245668, allCalculationResults[0].Pl3HeadAdjusted.Value, cTolerance); Assert.AreEqual(49.1, allCalculationResults[0].Pl3LocalLocationXMinUplift.Value, cTolerance); } /// /// Performs test BM04Opdrijven03 situation with a labile equilibirum 1D /// [Test] [Category("Slow")] public void BM04Opdrijven03SituatieMetEenLabielEvenwicht1D() { const string cFolderName = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\03 Situatie met een labiel evenwicht (1D)\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cFolderName); List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.UpliftVan, 1); Assert.IsTrue(allCalculationResults[0].IsUplift.Value); Assert.AreEqual(1.0, allCalculationResults[0].Pl3MinUplift.Value, cTolerance); Assert.AreEqual(-1.289245668, allCalculationResults[0].Pl3HeadAdjusted.Value, cTolerance); Assert.AreEqual(49.1, allCalculationResults[0].Pl3LocalLocationXMinUplift.Value, cTolerance); } /// /// performs test BM04Opdrijven04 situation with an inclined ditch bottom where uplift occurs 1D /// [Test] [Category("Slow")] public void BM04Opdrijven04SituatieMetEenSchuineSlootbodemEnOpdrijvenOp1Locatie1D() { const string cFolderName = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\04 Situatie met een schuine slootbodem en opdrijven op 1 locatie (1D)\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cFolderName); List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.UpliftVan, 1); Assert.IsTrue(allCalculationResults[0].IsUplift.Value); Assert.AreEqual(0.852055725, allCalculationResults[0].Pl3MinUplift.Value, cTolerance); Assert.AreEqual(-2.1657492, allCalculationResults[0].Pl3HeadAdjusted.Value, cTolerance); Assert.AreEqual(49.1, allCalculationResults[0].Pl3LocalLocationXMinUplift.Value, cTolerance); } /// /// Performs test BM04Opdrijven05 situation with soil layers aboven and below the phreatic line 1D /// [Test] [Category("Slow")] public void BM04Opdrijven05SituatieMetGrondlagenBovenEnOnderHetFreatischVlak1D() { const string cFolderName = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\05 Situatie met grondlagen boven en onder het freatisch vlak (1D)\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cFolderName); List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.Bishop, 1); bool? isUplift = allCalculationResults[0].IsUplift; Assert.IsFalse(isUplift != null && isUplift.Value); Assert.AreEqual(null, allCalculationResults[0].Pl3MinUplift); Assert.AreEqual(null, allCalculationResults[0].Pl3LocalLocationXMinUplift); } /// /// Performs test BM04Opdrijven06 situation with uplift on different locations along the 1D profile /// [Test] [Category("Slow")] public void BM04Opdrijven06SituatieMetOpdrijvenOpVerschillendeLocatiesLangsHetProfiel1D() { const string cFolderName = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\06 Situatie met verschillende opdrijflocaties (1D)\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cFolderName); List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.UpliftVan, 1); Assert.IsTrue(allCalculationResults[0].IsUplift.Value); // Values at bottom ditch dikeside Assert.AreEqual(0.820097604, allCalculationResults[0].Pl3MinUplift.Value, cTolerance); Assert.AreEqual(-1.289245668, allCalculationResults[0].Pl3HeadAdjusted.Value, cTolerance); Assert.AreEqual(49.1, allCalculationResults[0].Pl3LocalLocationXMinUplift.Value, cTolerance); } /// /// Performs test on Dijkring13, 3 different scenarios are tested, with different uplift potentials /// [Test] [Category("Slow")] [TestCase(1)] [TestCase(5)] public void Dijkring13NormalStabilityCalculationBishop(int maxCores) { const string cDikeFolder = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\Dijkring13-Sec1\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cDikeFolder); List allCalculationResults = ComputeStabilityInsideProject(cDikeFolder, MStabModelType.Bishop, 1, maxCores); // Following values are just taken from the Geo Stability calculation and not manually calculated Assert.AreEqual(0.785, allCalculationResults[0].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.998, allCalculationResults[1].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.792, allCalculationResults[2].StabilitySafetyFactor.Value, cTolerance); } /// /// Performs test on Dijkring13, 3 different scenarios are tested, with different uplift potentials /// [Test] [Category("Slow")] [TestCase(1)] [TestCase(5)] public void Dijkring13NormalStabilityCalculation(int maxCores) { const string cDikeFolder = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\Dijkring13-Sec1\Databronbestand.damx"; RemoveCalculationDirectoriesForProject(cDikeFolder); List allCalculationResults = ComputeStabilityInsideProject(cDikeFolder, MStabModelType.UpliftVan, 1, maxCores); // Following values are just taken from the Geo Stability calculation and not manually calculated Assert.AreEqual(0.696, allCalculationResults[0].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.964, allCalculationResults[1].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.738, allCalculationResults[2].StabilitySafetyFactor.Value, cTolerance); } /// /// Performs test on Dijkring13, 3 different scenarios are tested, with different uplift potentials /// [Test] [Category("Slow")] [TestCase(1)] [TestCase(5)] [TestCase(10)] public void Dijkring13NormalStabilityCalculationMultiCoreForMultiLocations(int maxCores) { const string cDikeFolder = @"..\..\..\..\..\data\benchmarks\Opdrijfberekeningen\Dijkring13-Sec1\DatabronbestandMulti.damx"; RemoveCalculationDirectoriesForProject(cDikeFolder); List allCalculationResults = ComputeStabilityInsideProject(cDikeFolder, MStabModelType.UpliftVan, 10, maxCores); // Following values are just taken from the Geo Stability calculation and not manually calculated Assert.AreEqual(30, allCalculationResults.Count); Assert.AreEqual(0.696, allCalculationResults[0].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.964, allCalculationResults[1].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.738, allCalculationResults[2].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.695, allCalculationResults[3].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.962, allCalculationResults[4].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.737, allCalculationResults[5].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.694, allCalculationResults[6].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.961, allCalculationResults[7].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.734, allCalculationResults[8].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.693, allCalculationResults[9].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.960, allCalculationResults[10].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.732, allCalculationResults[11].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.692, allCalculationResults[12].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.959, allCalculationResults[13].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.732, allCalculationResults[14].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.692, allCalculationResults[15].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.959, allCalculationResults[16].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.731, allCalculationResults[17].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.690, allCalculationResults[18].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.957, allCalculationResults[19].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.729, allCalculationResults[20].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.689, allCalculationResults[21].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.957, allCalculationResults[22].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.728, allCalculationResults[23].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.688, allCalculationResults[24].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.956, allCalculationResults[25].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.726, allCalculationResults[26].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.687, allCalculationResults[27].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.954, allCalculationResults[28].StabilitySafetyFactor.Value, cTolerance); Assert.AreEqual(0.725, allCalculationResults[29].StabilitySafetyFactor.Value, cTolerance); } /// /// Performs test BMStabilityInwardsNoAdaptation /// [Test] [Category("Slow")] public void BMStabilityInwardsNoAdaptation() { const string cFolderName = @"..\..\..\..\..\data\Benchmarks\Opdrijfberekeningen\StabilityInwards-NoAdaptation\Databronbestand.damx"; List allCalculationResults = ComputeStabilityInsideProject(cFolderName, MStabModelType.UpliftVan, 1); RemoveCalculationDirectoriesForProject(cFolderName); Assert.IsTrue(allCalculationResults[0].IsUplift.Value); Assert.AreEqual(0.767, allCalculationResults[0].StabilitySafetyFactor.Value, cTolerance); } #endregion Uplift }