// Copyright (C) Stichting Deltares 2019. 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; using System.Collections.Generic; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.MacroStability.CSharpWrapper.Input; using Deltares.MacroStability.CSharpWrapper.Output; using CharacteristicPointType = Deltares.DamEngine.Data.Geotechnics.CharacteristicPointType; using WaterPressureInterpolationModel = Deltares.DamEngine.Data.Geotechnics.WaterpressureInterpolationModel; using CharacteristicPoint = Deltares.MacroStability.CSharpWrapper.Input.CharacteristicPointType; using LogMessageType = Deltares.DamEngine.Data.Standard.Logging.LogMessageType; using ObjectExtensions = Deltares.DamEngine.Data.Standard.ObjectExtensions; using SearchAlgorithm = Deltares.MacroStability.CSharpWrapper.Input.SearchAlgorithm; using MessageType = Deltares.MacroStability.CSharpWrapper.Output.MessageType; using ShearStrengthModel = Deltares.DamEngine.Data.Geotechnics.ShearStrengthModel; using Soil = Deltares.MacroStability.CSharpWrapper.Input.Soil; using StabilityModelOptionType = Deltares.MacroStability.CSharpWrapper.Output.StabilityModelOptionType; using WaterPressureInterpolationModelKernel = Deltares.MacroStability.CSharpWrapper.Input.WaterPressureInterpolationModel; using ShearStrengthModelKernel = Deltares.MacroStability.CSharpWrapper.ShearStrengthModelType; namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo { public static class ConversionHelper { #region SearchMethod /// Converts SearchAlgorithm to MStabSearchMethod. /// The MacroStability search algorithm. /// /// public static MStabSearchMethod ConvertToDamSearchMethod(SearchAlgorithm searchAlgorithm) { if (searchAlgorithm != SearchAlgorithm.Grid && searchAlgorithm != SearchAlgorithm.Genetic) { throw new ArgumentException(String.Format("Unsupported search algorithm: {0}", searchAlgorithm)); } var translationTable = new Dictionary() { {SearchAlgorithm.Genetic, MStabSearchMethod.GeneticAlgorithm}, {SearchAlgorithm.Grid, MStabSearchMethod.Grid} }; return translationTable[searchAlgorithm]; } /// Converts MStabSearchMethod to SearchAlgorithm. /// The Dam search algorithm. /// /// public static SearchAlgorithm ConvertToMacroStabilitySearchMethod(MStabSearchMethod mStabSearchMethod) { var translationTable = new Dictionary() { {MStabSearchMethod.GeneticAlgorithm, SearchAlgorithm.Genetic}, {MStabSearchMethod.Grid, SearchAlgorithm.Grid} }; return translationTable[mStabSearchMethod]; } #endregion #region ModelType /// Converts ModelOption to the MStabModelType. /// This comes back from the kernel side so any model that can be matched is OK. /// The model option. /// the Dam MStabModelType public static MStabModelType ConvertToMStabModelType(StabilityModelOptionType modelOption) { // For the macrostability kernel, the only really supported option for now is UpliftVan. But the other two could be options in future version var translationTable = new Dictionary() { //{StabilityModelOptionOutput.Bishop, MStabModelType.BishopWti}, {StabilityModelOptionType.UpliftVan, MStabModelType.UpliftVan }, //{MacroStability.CSharpWrapper.Output.StabilityModelOption.Spencer, MStabModelType.UpliftSpencerWti} }; return translationTable[modelOption]; } /// Converts to ModelOptions type. /// the MStabModelType. /// the MacroStability ModelOption /// public static StabilityModelOptionType ConvertToModelOptions(MStabModelType mStabModelType) { // For the macrostability kernel, the only supported option for now is UpliftVan. if (mStabModelType != MStabModelType.UpliftVan) { throw new ArgumentException(String.Format("Unsupported MStabModelType: {0}", mStabModelType)); } var translationTable = new Dictionary() { {MStabModelType.UpliftVan, StabilityModelOptionType.UpliftVan} }; return translationTable[mStabModelType]; } /// Converts ModelOption to the MStabModelType. /// This comes back from the kernel side so any model that can be matched is OK. /// The model option. /// the Dam MStabModelType public static MStabModelType ConvertToMStabModelTypeFromOutput(StabilityModelOptionType modelOption) { // For the macrostability kernel, the only really supported option for now is UpliftVan. But the other two could be options in future version var translationTable = new Dictionary() { {StabilityModelOptionType.Bishop, MStabModelType.BishopWti}, {StabilityModelOptionType.UpliftVan, MStabModelType.UpliftVan }, //{MacroStability.CSharpWrapper.Output.StabilityModelOption.Spencer, MStabModelType.UpliftSpencerWti} }; return translationTable[modelOption]; } /// Converts to ModelOptions type. /// the MStabModelType. /// the MacroStability ModelOption /// public static StabilityModelOptionType ConvertToModelOptionsOutput(MStabModelType mStabModelType) { // For the macrostability kernel, the only supported option for now is UpliftVan. if (mStabModelType != MStabModelType.UpliftVan) { throw new ArgumentException(String.Format("Unsupported MStabModelType: {0}", mStabModelType)); } var translationTable = new Dictionary() { {MStabModelType.UpliftVan, StabilityModelOptionType.UpliftVan} }; return translationTable[mStabModelType]; } #endregion #region GridOrientation /// Converts to MStabGridPosition. /// The grid orientation. /// public static MStabGridPosition ConvertToMStabGridPosition(Orientation gridOrientation) { var translationTable = new Dictionary() { {Orientation.Inwards, MStabGridPosition.Right}, {Orientation.Outwards, MStabGridPosition.Left} }; return translationTable[gridOrientation]; } /// Converts to GridOrientation. /// The MStabGridPosition. /// public static Orientation ConvertToGridOrientation(MStabGridPosition mStabGridPosition) { var translationTable = new Dictionary() { {MStabGridPosition.Right, Orientation.Inwards}, {MStabGridPosition.Left, Orientation.Outwards} }; return translationTable[mStabGridPosition]; } #endregion #region Soil /// Converts to MacroStability soil. /// The Dam soil. /// The MacroStability Soil. public static Soil ConvertToMacroStabilitySoil(Data.Geotechnics.Soil soil) { var macroStabilitySoil = new Soil() { Name = soil.Name, AbovePhreaticLevel = soil.AbovePhreaticLevel, BelowPhreaticLevel = soil.BelowPhreaticLevel, Cohesion = soil.Cohesion, FrictionAngle = soil.FrictionAngle, RRatio = soil.RRatio, RatioCuPc = soil.RatioCuPc, StrengthIncreaseExponent = soil.StrengthIncreaseExponent, UseSoilClassification = false, // Soil type is not given so make sure it is not used. BondStressCurve = null // these are not supported in DAM so set to null. }; if (soil.ShearStrengthModel != null) { macroStabilitySoil.ShearStrengthAbovePhreaticLevelModel = ConvertToMacroStabilityShearStrengthModel(soil.ShearStrengthModel.Value); macroStabilitySoil.ShearStrengthBelowPhreaticLevelModel = ConvertToMacroStabilityShearStrengthModel(soil.ShearStrengthModel.Value); } switch (soil.DilatancyType) { case DilatancyType.MinusPhi: macroStabilitySoil.Dilatancy = -macroStabilitySoil.FrictionAngle; // -Phi (FrictionAngle) break; case DilatancyType.Phi: macroStabilitySoil.Dilatancy = macroStabilitySoil.FrictionAngle; // Phi (FrictionAngle) break; default: macroStabilitySoil.Dilatancy = 0.0; // Zero and default break; } return macroStabilitySoil; } /// Converts to Dam soil. /// The MacroStability soil. /// The Dam soil. /// public static Data.Geotechnics.Soil ConvertToDamSoil(Soil soil) { double tolerance = 0.00001; var damSoil = new Data.Geotechnics.Soil() { Name = soil.Name, AbovePhreaticLevel = soil.AbovePhreaticLevel, BelowPhreaticLevel = soil.BelowPhreaticLevel, Cohesion = soil.Cohesion, FrictionAngle = soil.FrictionAngle, RRatio = soil.RRatio, RatioCuPc = soil.RatioCuPc, // RheologicalCoefficient = 1.07, // is purely needed for Nails which are NOT yet to be implemented //Todo #Bka We keep this as "truth" for now. But maybe Dam should become above/below too ShearStrengthModel = ConvertToDamShearStrengthModel(soil.ShearStrengthAbovePhreaticLevelModel), StrengthIncreaseExponent = soil.StrengthIncreaseExponent, // Following parameters are not available in MacroStability soil and will not be translated (they are for Piping). //CuBottom = 0.00, //DiameterD70 = 0.00, //CuTop = 0.00, //DiameterD90 = 0.00, //DryUnitWeight = 0.00, //Ocr = 0.00, //PermeabKx = 0.00, //PoP = 0.00, //SlopeRestProfile = 0.00, //SoilType = SoilType.Clay, //UseDefaultShearStrengthModel = false, //UsePop = true, //WhitesConstant = 0.00, }; if (ObjectExtensions.AlmostEquals(soil.Dilatancy, soil.FrictionAngle, tolerance)) { damSoil.DilatancyType = DilatancyType.Phi; } else if (ObjectExtensions.AlmostEquals(soil.Dilatancy, -soil.FrictionAngle, tolerance)) { damSoil.DilatancyType = DilatancyType.MinusPhi; } else if (ObjectExtensions.AlmostEquals(soil.Dilatancy, 0.0, tolerance)) { damSoil.DilatancyType = DilatancyType.Zero; } else { throw new FormatException(string.Format("Cannot determine DilatancyType; Dilatancy = {0}, FrictionAngle = {1}", soil.Dilatancy, soil.FrictionAngle)); } return damSoil; } /// Converts to dam ShearStrengthModel. /// The kernel ShearStrengthModel. /// public static ShearStrengthModel ConvertToDamShearStrengthModel(ShearStrengthModelKernel kernelShearStrengthModel) { var translationTable = new Dictionary() { {ShearStrengthModelKernel.MohrCoulomb, ShearStrengthModel.CPhi}, {ShearStrengthModelKernel.Shansep, ShearStrengthModel.SuCalculated} }; return translationTable[kernelShearStrengthModel]; } /// Converts to macro stability ShearStrengthModel. /// The dam ShearStrengthModel. /// /// public static ShearStrengthModelKernel ConvertToMacroStabilityShearStrengthModel(ShearStrengthModel damShearStrengthModel) { if (damShearStrengthModel == ShearStrengthModel.SuCalculatedWithYield || damShearStrengthModel == ShearStrengthModel.None || damShearStrengthModel == ShearStrengthModel.PseudoValues || damShearStrengthModel == ShearStrengthModel.StressTable || damShearStrengthModel == ShearStrengthModel.SuGradient || damShearStrengthModel == ShearStrengthModel.SuMeasured || damShearStrengthModel == ShearStrengthModel.CPhiOrSuCalculated) { throw new ArgumentException(string.Format("Cannot convert dam ShearStrengthModel: {0}", damShearStrengthModel)); } var translationTable = new Dictionary() { {ShearStrengthModel.CPhi, ShearStrengthModelKernel.MohrCoulomb}, {ShearStrengthModel.SuCalculated, ShearStrengthModelKernel.Shansep} }; return translationTable[damShearStrengthModel]; } #endregion #region WaterpressureInterpolationModel /// Converts to macro stability waterpressure interpolation model. /// The waterpressure interpolation model. /// public static WaterPressureInterpolationModelKernel ConvertToMacroStabilityWaterpressureInterpolationModel(WaterPressureInterpolationModel waterpressureInterpolationModel) { var translationTable = new Dictionary() { {WaterPressureInterpolationModel.Automatic, WaterPressureInterpolationModelKernel.Automatic}, {WaterPressureInterpolationModel.Hydrostatic, WaterPressureInterpolationModelKernel.Hydrostatic} }; return translationTable[waterpressureInterpolationModel]; } /// Converts to dam waterpressure interpolation model. /// The waterpressure interpolation model. /// public static WaterpressureInterpolationModel ConvertToDamWaterpressureInterpolationModel(WaterPressureInterpolationModelKernel waterpressureInterpolationModel) { var translationTable = new Dictionary() { {WaterPressureInterpolationModelKernel.Automatic, WaterPressureInterpolationModel.Automatic}, {WaterPressureInterpolationModelKernel.Hydrostatic, WaterPressureInterpolationModel.Hydrostatic} }; return translationTable[waterpressureInterpolationModel]; } #endregion #region CharacteristicPointType /// Converts the type of to dam characteristic point. /// Type of the kernel characteristic point. /// public static CharacteristicPointType ConvertToDamCharacteristicPointType(CharacteristicPoint kernelCharacteristicPointType) { var translationTable = new Dictionary() { {CharacteristicPoint.BottomDitchDikeSide, CharacteristicPointType.BottomDitchDikeSide}, {CharacteristicPoint.BottomDitchPolderSide, CharacteristicPointType.BottomDitchPolderSide}, {CharacteristicPoint.DikeToeAtPolder, CharacteristicPointType.DikeToeAtPolder}, {CharacteristicPoint.DikeToeAtRiver, CharacteristicPointType.DikeToeAtRiver}, {CharacteristicPoint.DikeTopAtPolder, CharacteristicPointType.DikeTopAtPolder}, {CharacteristicPoint.DikeTopAtRiver, CharacteristicPointType.DikeTopAtRiver}, {CharacteristicPoint.DitchDikeSide, CharacteristicPointType.DitchDikeSide}, {CharacteristicPoint.DitchPolderSide, CharacteristicPointType.DitchPolderSide}, {CharacteristicPoint.None, CharacteristicPointType.None}, {CharacteristicPoint.ShoulderBaseInside, CharacteristicPointType.ShoulderBaseInside}, {CharacteristicPoint.ShoulderBaseOutside, CharacteristicPointType.ShoulderBaseOutside}, {CharacteristicPoint.ShoulderTopInside, CharacteristicPointType.ShoulderTopInside}, {CharacteristicPoint.ShoulderTopOutside, CharacteristicPointType.ShoulderTopOutside}, {CharacteristicPoint.SurfaceLevelInside, CharacteristicPointType.SurfaceLevelInside}, {CharacteristicPoint.SurfaceLevelOutside, CharacteristicPointType.SurfaceLevelOutside}, {CharacteristicPoint.TrafficLoadInside, CharacteristicPointType.TrafficLoadInside}, {CharacteristicPoint.TrafficLoadOutside, CharacteristicPointType.TrafficLoadOutside} }; return translationTable[kernelCharacteristicPointType]; } /// Converts the type of to macro stability characteristic point. /// Type of the dam characteristic point. /// public static CharacteristicPoint ConvertToMacroStabilityCharacteristicPointType(CharacteristicPointType damCharacteristicPointType) { var translationTable = new Dictionary() { {CharacteristicPointType.BottomDitchPolderSide, CharacteristicPoint.BottomDitchPolderSide}, {CharacteristicPointType.BottomDitchDikeSide, CharacteristicPoint.BottomDitchDikeSide}, {CharacteristicPointType.DikeToeAtPolder, CharacteristicPoint.DikeToeAtPolder}, {CharacteristicPointType.DikeToeAtRiver, CharacteristicPoint.DikeToeAtRiver}, {CharacteristicPointType.DikeTopAtPolder, CharacteristicPoint.DikeTopAtPolder}, {CharacteristicPointType.DikeTopAtRiver, CharacteristicPoint.DikeTopAtRiver}, {CharacteristicPointType.DitchDikeSide, CharacteristicPoint.DitchDikeSide}, {CharacteristicPointType.DitchPolderSide, CharacteristicPoint.DitchPolderSide}, {CharacteristicPointType.None, CharacteristicPoint.None}, {CharacteristicPointType.ShoulderBaseInside, CharacteristicPoint.ShoulderBaseInside}, {CharacteristicPointType.ShoulderBaseOutside, CharacteristicPoint.ShoulderBaseOutside}, {CharacteristicPointType.ShoulderTopInside, CharacteristicPoint.ShoulderTopInside}, {CharacteristicPointType.ShoulderTopOutside, CharacteristicPoint.ShoulderTopOutside}, {CharacteristicPointType.SurfaceLevelInside, CharacteristicPoint.SurfaceLevelInside}, {CharacteristicPointType.SurfaceLevelOutside, CharacteristicPoint.SurfaceLevelOutside}, {CharacteristicPointType.TrafficLoadInside, CharacteristicPoint.TrafficLoadInside}, {CharacteristicPointType.TrafficLoadOutside, CharacteristicPoint.TrafficLoadOutside} }; return translationTable[damCharacteristicPointType]; } #endregion #region LogMessages /// /// Converts the kernel validation result type to log message type of DamEngine. /// /// Type of the message. /// public static MessageType ConvertLogMessageTypeToKernelLogMessageType(LogMessageType messageType) { var translationTable = new Dictionary() { {LogMessageType.Info, MessageType.Info}, {LogMessageType.Warning, MessageType.Warning}, {LogMessageType.Error, MessageType.Error} }; return translationTable[messageType]; } /// /// Converts the kernel log message type to log message type of DamEngine. /// /// Type of the message. /// public static LogMessageType ConvertKernelLogMessageTypeToLogMessageType(MessageType messageType) { var translationTable = new Dictionary() { {MessageType.Info, LogMessageType.Info}, {MessageType.Warning, LogMessageType.Warning}, {MessageType.Error, LogMessageType.Error} }; return translationTable[messageType]; } #endregion public static CalculationResult ConvertToDamResultType(CalculationResultType calculationResult) { var translationTable = new Dictionary() { {CalculationResultType.NoRun, CalculationResult.NoRun}, {CalculationResultType.Succeeded, CalculationResult.Succeeded}, {CalculationResultType.NoInput, CalculationResult.NoInput}, {CalculationResultType.NoLicense, CalculationResult.NoLicense}, {CalculationResultType.UserAbort, CalculationResult.UserAbort}, {CalculationResultType.InvalidInputStructure, CalculationResult.InvalidInputStructure}, {CalculationResultType.InvalidInputData, CalculationResult.InvalidInputData}, {CalculationResultType.RunFailed, CalculationResult.RunFailed}, {CalculationResultType.UnexpectedError, CalculationResult.UnexpectedError} }; return translationTable[calculationResult]; } public static CalculationResultType ConvertToMacroStabilityResultType(CalculationResult calculationResult) { var translationTable = new Dictionary() { {CalculationResult.NoRun, CalculationResultType.NoRun}, {CalculationResult.Succeeded, CalculationResultType.Succeeded}, {CalculationResult.NoInput, CalculationResultType.NoInput}, {CalculationResult.NoLicense, CalculationResultType.NoLicense}, {CalculationResult.UserAbort, CalculationResultType.UserAbort}, {CalculationResult.InvalidInputStructure, CalculationResultType.InvalidInputStructure}, {CalculationResult.InvalidInputData, CalculationResultType.InvalidInputData}, {CalculationResult.RunFailed, CalculationResultType.RunFailed}, {CalculationResult.UnexpectedError, CalculationResultType.UnexpectedError} }; return translationTable[calculationResult]; } } }