Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/InterfaceConversionHelper.cs =================================================================== diff -u -r6346 -r6350 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/InterfaceConversionHelper.cs (.../InterfaceConversionHelper.cs) (revision 6346) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/InterfaceConversionHelper.cs (.../InterfaceConversionHelper.cs) (revision 6350) @@ -174,7 +174,10 @@ return translationTable[damCharacteristicPointType]; } - public static SoilType ConvertToMacroStabilitySoil(Data.Geotechnics.Soil soil) + /// Converts to MacroStability soil. + /// The Dam soil. + /// The MacroStability Soil. + public static SoilType ConvertToMacroStabilitySoil(Soil soil) { var macroStabilitySoil = new SoilType { @@ -231,6 +234,54 @@ return macroStabilitySoil; } + /// Converts to Dam soil. + /// The MacroStability soil. + /// The Dam soil. + /// + public static Soil ConvertToDamSoil(SoilType soil) + { + var damSoil = new Soil + { + Name = soil.Name, + AbovePhreaticLevel = soil.AbovePhreaticLevel, + BelowPhreaticLevel = soil.BelowPhreaticLevel, + Cohesion = soil.Cohesion, + FrictionAngle = soil.FrictionAngle, + RatioCuPc = soil.RatioCuPc, + StrengthIncreaseExponent = soil.StrengthIncreaseExponent, + //Todo #Bka We keep this as "truth" for now. But maybe Dam should become above/below too + ShearStrengthModel = ConvertToDamShearStrengthModel(soil.ShearStrengthAbovePhreaticLevelModel) + }; + + if (soil.SigmaTauTable != null) + { + damSoil.SigmaTauCurve = new SigmaTauCurve(); + foreach (SoilTypeSigmaTauTablePoint point in soil.SigmaTauTable) + { + damSoil.SigmaTauCurve.Points.Add(new SigmaTauPoint + { + Sigma = point.Sigma, + Tau = point.Tau + }); + } + } + + if (soil.SuTable != null) + { + damSoil.SuTableCurve = new SuTableCurve(); + foreach (SoilTypeSuTablePoint point in soil.SuTable) + { + damSoil.SuTableCurve.Points.Add(new SigmaSuPoint() + { + Sigma = point.EffectiveStress, + Su = point.Su + }); + } + } + + return damSoil; + } + /// Converts to macro stability ShearStrengthModel. /// The dam ShearStrengthModel. /// @@ -255,11 +306,34 @@ return translationTable[damShearStrengthModel]; } - /// Converts to macro stability waterpressure interpolation model. - /// The waterpressure interpolation model. + /// Converts to dam ShearStrengthModel. + /// The kernel ShearStrengthModel. /// - public static WaterPressureInterpolationModelType ConvertToMacroStabilityWaterpressureInterpolationModel(WaterpressureInterpolationModel waterpressureInterpolationModel) + public static ShearStrengthModel ConvertToDamShearStrengthModel(ShearStrengthModelType kernelShearStrengthModel) { + var translationTable = new Dictionary + { + { + ShearStrengthModelType.MohrCoulomb, ShearStrengthModel.CPhi + }, + { + ShearStrengthModelType.Shansep, ShearStrengthModel.SuCalculated + }, + { + ShearStrengthModelType.SigmaTauTable, ShearStrengthModel.SigmaTauCurve + }, + { + ShearStrengthModelType.SuTable, ShearStrengthModel.SuTable + } + }; + return translationTable[kernelShearStrengthModel]; + } + + /// Converts to macro stability water pressure interpolation model. + /// The water pressure interpolation model. + /// + public static WaterPressureInterpolationModelType ConvertToMacroStabilityWaterPressureInterpolationModel(WaterpressureInterpolationModel waterPressureInterpolationModel) + { var translationTable = new Dictionary { { @@ -269,6 +343,6 @@ WaterpressureInterpolationModel.Hydrostatic, WaterPressureInterpolationModelType.Hydrostatic } }; - return translationTable[waterpressureInterpolationModel]; + return translationTable[waterPressureInterpolationModel]; } } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/InterfaceConversionHelperTests.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/InterfaceConversionHelperTests.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/InterfaceConversionHelperTests.cs (revision 6350) @@ -0,0 +1,129 @@ +// 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.MacroStability.Io.XmlInput; +using KellermanSoftware.CompareNetObjects; +using NUnit.Framework; + +namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityCommon; + +[TestFixture] +public class InterfaceConversionHelperTests +{ + [Test] + public void GivenMacroStabilitySoilWhenConvertingToDamSoilAndBackThenResultEqualsOriginal() + { + // Given MacroStability Soil + var macroStabilitySoil = new SoilType() + { + Name = "MacroStabilitySoil", + AbovePhreaticLevel = 1.01, + BelowPhreaticLevel = 1.02, + Cohesion = 1.03, + FrictionAngle = 1.04, + Dilatancy = 1.04, + RatioCuPc = 1.06, + ShearStrengthAbovePhreaticLevelModel = ShearStrengthModelType.MohrCoulomb, + ShearStrengthBelowPhreaticLevelModel = ShearStrengthModelType.MohrCoulomb, + StrengthIncreaseExponent = 1.08, + UseSoilClassification = false, // must be false + SigmaTauTable = [], + SuTable = [], + BondStressCurve = null // must be null + }; + + // When Converting to DamSoil and back + Data.Geotechnics.Soil damSoil = InterfaceConversionHelper.ConvertToDamSoil(macroStabilitySoil); + SoilType actualMacroStabilitySoil = InterfaceConversionHelper.ConvertToMacroStabilitySoil(damSoil); + + // Then result equals original + var compare = new CompareLogic + { + Config = + { + MaxDifferences = 100 + } + }; + ComparisonResult result = compare.Compare(macroStabilitySoil, actualMacroStabilitySoil); + Assert.That(result.Differences, Is.Empty, "Differences found converting/reconverting Soil but this ok now if diff = 3"); + } + + [Test] + public void GivenMacroStabilitySoilWithSuAndSigmaTauTableWhenConvertingToDamSoilAndBackThenResultEqualsOriginal() + { + // Given MacroStability Soil with filled Su and SigmaTau table + var sigmaTauTable = new SoilTypeSigmaTauTablePoint[2]; + sigmaTauTable[0] = new SoilTypeSigmaTauTablePoint + { + Sigma = 1.1, + Tau = 2.1 + }; + sigmaTauTable[1] = new SoilTypeSigmaTauTablePoint + { + Sigma = 2.1, + Tau = 3.1 + }; + var suTable = new SoilTypeSuTablePoint[2]; + suTable[0] = new SoilTypeSuTablePoint + { + Su = 0.1, + EffectiveStress = 10.1 + }; + suTable[1] = new SoilTypeSuTablePoint + { + Su = 1.21, + EffectiveStress = 13.4 + }; + var macroStabilitySoil = new SoilType() + { + Name = "MacroStabilitySoil", + AbovePhreaticLevel = 1.01, + BelowPhreaticLevel = 1.02, + Cohesion = 1.03, + FrictionAngle = 1.04, + Dilatancy = 1.04, + RatioCuPc = 1.06, + ShearStrengthAbovePhreaticLevelModel = ShearStrengthModelType.MohrCoulomb, + ShearStrengthBelowPhreaticLevelModel = ShearStrengthModelType.MohrCoulomb, + StrengthIncreaseExponent = 1.08, + UseSoilClassification = false, // must be false + SigmaTauTable = sigmaTauTable, + SuTable = suTable, + BondStressCurve = null // must be null + }; + + // When Converting to DamSoil and back + Data.Geotechnics.Soil damSoil = InterfaceConversionHelper.ConvertToDamSoil(macroStabilitySoil); + SoilType actualMacroStabilitySoil = InterfaceConversionHelper.ConvertToMacroStabilitySoil(damSoil); + + // Then result equals original + var compare = new CompareLogic + { + Config = + { + MaxDifferences = 100 + } + }; + ComparisonResult result = compare.Compare(macroStabilitySoil, actualMacroStabilitySoil); + Assert.That(result.Differences, Is.Empty, "Differences found converting/reconverting Soil but this ok now if diff = 3"); + } +} \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillMacroStabilityInterfaceInputFromEngine.cs =================================================================== diff -u -r6346 -r6350 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillMacroStabilityInterfaceInputFromEngine.cs (.../FillMacroStabilityInterfaceInputFromEngine.cs) (revision 6346) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillMacroStabilityInterfaceInputFromEngine.cs (.../FillMacroStabilityInterfaceInputFromEngine.cs) (revision 6350) @@ -458,7 +458,7 @@ GeometrySurface = registry.GetId(damSoilLayer2D.GeometrySurface), Soil = registry.GetId(damSoilLayer2D.Soil), WaterPressureInterpolationModelSpecified = true, - WaterPressureInterpolationModel = InterfaceConversionHelper.ConvertToMacroStabilityWaterpressureInterpolationModel(damSoilLayer2D + WaterPressureInterpolationModel = InterfaceConversionHelper.ConvertToMacroStabilityWaterPressureInterpolationModel(damSoilLayer2D .WaterpressureInterpolationModel) }; kernelSoilProfile.SoilSurfaces[i] = kernelSoilLayer2D;