// Copyright (C) Stichting Deltares 2025. 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 Deltares.Dam.Data; using Deltares.Dam.Data.DamEngineIo; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using Deltares.Standard.Logging; using NUnit.Framework; namespace Deltares.Dam.TestHelper { /// /// Input parameters for computing a stability project /// public class ComputeStabilityProjectParameters { public List LocationNames { get; set; } = null; public StabilityModelType ModelType { get; set; } = StabilityModelType.Bishop; public bool IsStabilityInside { get; set; } = true; public int ExpectedLocations { get; set; } = 1; public int MaxCores { get; set; } = 1; } /// /// Helper class to compute stability projects /// public class ComputeHelper { /// /// Compute stability project /// /// The filename of the project to compute /// Parameteres to compute a stability project /// The log messages of the computation /// public static List ComputeStabilityProject(string projectFilename, ComputeStabilityProjectParameters computeStabilityProjectParameters, out List logMessages) { using DamProjectData damProjectData = ProjectLoader.LoadProjectData(projectFilename); Assert.That(damProjectData.WaterBoard.Dikes.Count, Is.EqualTo(1)); Dike dike = damProjectData.WaterBoard.Dikes[0]; Assert.That(dike.Locations.Count, Is.EqualTo(computeStabilityProjectParameters.ExpectedLocations)); // Specify calculation damProjectData.MaxCalculationCores = computeStabilityProjectParameters.MaxCores; damProjectData.DamProjectCalculationSpecification.CurrentSpecification.StabilityModelType = computeStabilityProjectParameters.ModelType; damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismeParamatersMStab .MStabParameters.SearchMethod = StabilitySearchMethod.Grid; if (computeStabilityProjectParameters.IsStabilityInside) { damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType = FailureMechanismSystemType.StabilityInside; } else { damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType = FailureMechanismSystemType.StabilityOutside; } // Determine locations to calculate // If no location names specified, run all locations foreach (LocationJob locationJob in damProjectData.LocationJobs) { if (computeStabilityProjectParameters.LocationNames == null || computeStabilityProjectParameters.LocationNames.Count == 0) { // Run all locations locationJob.Run = true; } else { // Only run specified locations locationJob.Run = computeStabilityProjectParameters.LocationNames.Contains(locationJob.Location.Name); } } DamProjectCalculationSpecification.SelectedAnalysisType = AnalysisType.NoAdaption; Input input = FillXmlInputFromDamUi.CreateInput(damProjectData); string inputXml = DamXmlSerialization.SaveInputAsXmlString(input); #if DEBUG // Next line for debugging DamXmlSerialization.SaveInputAsXmlFile("InputForDebugging.xml", input); #endif 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); #if DEBUG // Next line for debugging DamXmlSerialization.SaveOutputAsXmlFile("OutputForDebugging.xml", output); #endif FillDamUiFromXmlOutput.AddOutputToDamProjectData(damProjectData, output); } List allCalculationResults = damProjectData.DesignCalculations; logMessages = damProjectData.CalculationMessages; return allCalculationResults; } } }