// 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
{
public class ComputeHelper
{
///
/// Compute stability project
///
///
///
///
///
///
///
///
public static List ComputeStabilityProject(string projectFilename, StabilityModelType modelType, bool isStabilityInside,
int expectedLocations, int maxCores, 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(expectedLocations));
// Specify calculation
damProjectData.MaxCalculationCores = maxCores;
damProjectData.DamProjectCalculationSpecification.CurrentSpecification.StabilityModelType = modelType;
damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismeParamatersMStab
.MStabParameters.SearchMethod = StabilitySearchMethod.Grid;
if (isStabilityInside)
{
damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType = FailureMechanismSystemType.StabilityInside;
}
else
{
damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType = FailureMechanismSystemType.StabilityOutside;
}
foreach (var locationJob in damProjectData.LocationJobs)
{
locationJob.Run = true;
}
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;
}
}
}