Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelOutputTests.cs =================================================================== diff -u -r6371 -r6379 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelOutputTests.cs (.../EngineToMacroStabilityKernelOutputTests.cs) (revision 6371) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/EngineToMacroStabilityKernelOutputTests.cs (.../EngineToMacroStabilityKernelOutputTests.cs) (revision 6379) @@ -22,6 +22,7 @@ using System.Collections.Generic; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards; +using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Data.Standard.Logging; using Deltares.MacroStability.Io.XmlOutput; using NUnit.Framework; @@ -32,21 +33,44 @@ public class EngineToMacroStabilityKernelOutputTests { [Test] - public void GivenKernelOutputWhenTransferToDamEngineThenDataIsEqual() + [TestCase(StabilityModelOption.Bishop, false)] + [TestCase(StabilityModelOption.Bishop, true)] + [TestCase(StabilityModelOption.UpliftVan, true)] + public void GivenKernelOutputWhenTransferToDamEngineThenDataIsEqual(StabilityModelOption modelOption, bool isSucceeded) { // Given - FullOutputModelType kernelOutput = CreateFullOutputModel(); - var damEngineOutput = new MacroStabilityOutput(); + FullOutputModelType kernelOutput = CreateFullOutputModel(modelOption); + var damEngineOutput = new MacroStabilityOutput + { + StabilityOutputItems = [] + }; // When FillEngineFromMacroStabilityKernelOutput.FillDamProjectDataFromKernelModel(kernelOutput, damEngineOutput, out List logMessages); // Then Assert.That(logMessages, Is.Not.Null); + Assert.That(logMessages, Has.Count.EqualTo(0)); + CompareOutput(kernelOutput, damEngineOutput); } - private FullOutputModelType CreateFullOutputModel() + private void CompareOutput(FullOutputModelType kernelOutput, MacroStabilityOutput damEngineOutput) { - return new FullOutputModelType(); + Assert.That(damEngineOutput.StabilityOutputItems[0].CalculationResult, Is.EqualTo(kernelOutput.StabilityOutput.Succeeded ? CalculationResult.Succeeded : CalculationResult.RunFailed)); + Assert.That(damEngineOutput.StabilityOutputItems[0].SafetyFactor, Is.EqualTo(kernelOutput.StabilityOutput.SafetyFactor)); + Assert.That(damEngineOutput.StabilityOutputItems[0].StabilityModelType, Is.EqualTo(OutputConversionHelper.ConvertToStabilityModelType(kernelOutput.StabilityOutput.ModelOption))); } + + private FullOutputModelType CreateFullOutputModel(StabilityModelOption modelOption) + { + var fullOutputModel = new FullOutputModelType + { + StabilityOutput = new StabilityOutputType(), + PreprocessingOutput = new PreprocessingOutputType() + }; + fullOutputModel.StabilityOutput.SafetyFactor = 2.34; + fullOutputModel.StabilityOutput.Succeeded = false; + fullOutputModel.StabilityOutput.ModelOption = modelOption; + return fullOutputModel; + } } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/OutputConversionHelper.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/OutputConversionHelper.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/OutputConversionHelper.cs (revision 6379) @@ -0,0 +1,70 @@ +// 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.Collections.Generic; +using Deltares.DamEngine.Data.General; +using Deltares.MacroStability.Io.XmlOutput; + +namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo; + +/// +/// Conversion methods between the MacroStability kernel and the Dam Engine. +/// +public abstract class OutputConversionHelper +{ + /// Converts ModelOption to the StabilityModelType. + /// This comes back from the kernel side so any model that can be matched is OK. + /// The model option. + /// the Dam StabilityModelType + public static StabilityModelType ConvertToStabilityModelType(StabilityModelOption stabilityModelOption) + { + var translationTable = new Dictionary + { + { + StabilityModelOption.Bishop, StabilityModelType.Bishop + }, + { + StabilityModelOption.UpliftVan, StabilityModelType.UpliftVan + } + // Spencer and Fellenius are not used in the Dam Engine + }; + return translationTable[stabilityModelOption]; + } + + /// Converts ModelOption to the StabilityModelType. + /// This comes back from the kernel side so any model that can be matched is OK. + /// The model option. + /// the Dam StabilityModelType + public static StabilityModelOption ConvertToStabilityModelOption(StabilityModelType stabilityModelType) + { + var translationTable = new Dictionary + { + { + StabilityModelType.Bishop, StabilityModelOption.Bishop + }, + { + StabilityModelType.UpliftVan, StabilityModelOption.UpliftVan + } + // BishopUpliftVan is not used in the kernel + }; + return translationTable[stabilityModelType]; + } +} \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/OutputConversionHelperTests.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/OutputConversionHelperTests.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/OutputConversionHelperTests.cs (revision 6379) @@ -0,0 +1,46 @@ +// 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 Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo; +using Deltares.DamEngine.Data.General; +using Deltares.MacroStability.Io.XmlOutput; +using NUnit.Framework; + +namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityCommon.MacroStabilityIo; + +public class OutputConversionHelperTests +{ + [Test] + [TestCase(StabilityModelOption.Bishop, StabilityModelType.Bishop)] + [TestCase(StabilityModelOption.UpliftVan, StabilityModelType.UpliftVan)] + public void CanConvertToStabilityModelType(StabilityModelOption modelOption, StabilityModelType stabilityModelType) + { + Assert.That(OutputConversionHelper.ConvertToStabilityModelType(modelOption), Is.EqualTo(stabilityModelType)); + } + + [Test] + [TestCase(StabilityModelType.Bishop, StabilityModelOption.Bishop)] + [TestCase(StabilityModelType.UpliftVan, StabilityModelOption.UpliftVan)] + public void CanConvertToStabilityModelOption(StabilityModelType stabilityModelType, StabilityModelOption modelOption) + { + Assert.That(OutputConversionHelper.ConvertToStabilityModelOption(stabilityModelType), Is.EqualTo(modelOption)); + } +} \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillEngineFromMacroStabilityKernelOutput.cs =================================================================== diff -u -r6371 -r6379 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillEngineFromMacroStabilityKernelOutput.cs (.../FillEngineFromMacroStabilityKernelOutput.cs) (revision 6371) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillEngineFromMacroStabilityKernelOutput.cs (.../FillEngineFromMacroStabilityKernelOutput.cs) (revision 6379) @@ -21,16 +21,32 @@ using System.Collections.Generic; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards; +using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Data.Standard.Logging; using Deltares.MacroStability.Io.XmlOutput; namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo; public static class FillEngineFromMacroStabilityKernelOutput { + /// + /// Transfer all properties from the kernel output to the dam project data. + /// + /// The kernel output data + /// The Engine output data + /// The log messages public static void FillDamProjectDataFromKernelModel(FullOutputModelType fullOutputModel, MacroStabilityOutput macroStabilityOutput, out List logMessages) { logMessages = new List(); + macroStabilityOutput.StabilityOutputItems.Add(new MacroStabilityOutputItem()); + TransferProperties(fullOutputModel.StabilityOutput, macroStabilityOutput.StabilityOutputItems[0], logMessages); } + + private static void TransferProperties(StabilityOutputType stabilityOutput, MacroStabilityOutputItem macroStabilityOutputItem, List logMessages) + { + macroStabilityOutputItem.CalculationResult = stabilityOutput.Succeeded ? CalculationResult.Succeeded : CalculationResult.RunFailed; + macroStabilityOutputItem.SafetyFactor = stabilityOutput.SafetyFactor; + macroStabilityOutputItem.StabilityModelType = OutputConversionHelper.ConvertToStabilityModelType(stabilityOutput.ModelOption); + } } \ No newline at end of file