// 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.MacroStability.Data; using Deltares.MacroStability.Geometry; using Deltares.MacroStability.Standard; using CharacteristicPointType = Deltares.DamEngine.Data.Geotechnics.CharacteristicPointType; using LogMessageType = Deltares.DamEngine.Data.Standard.Logging.LogMessageType; using ObjectExtensions = Deltares.DamEngine.Data.Standard.ObjectExtensions; using ShearStrengthModel = Deltares.DamEngine.Data.Geotechnics.ShearStrengthModel; using Soil = Deltares.MacroStability.Geometry.Soil; using WaterpressureInterpolationModel = Deltares.MacroStability.Geometry.WaterpressureInterpolationModel; 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. /// The model option. /// the Dam MStabModelType public static MStabModelType ConvertToMStabModelType(ModelOptions modelOption) { // For the macrostability kernel, the only supported option for now is UpliftVan. var translationTable = new Dictionary() { {ModelOptions.UpliftVan, MStabModelType.UpliftVanWti} }; return translationTable[modelOption]; } /// Converts to ModelOptions type. /// the MStabModelType. /// the MacroStability ModelOption /// public static ModelOptions ConvertToModelOptions(MStabModelType mStabModelType) { // For the macrostability kernel, the only supported option for now is UpliftVan. if (mStabModelType != MStabModelType.UpliftVanWti) { throw new ArgumentException(String.Format("Unsupported MStabModelType: {0}", mStabModelType)); } var translationTable = new Dictionary() { {MStabModelType.UpliftVanWti, ModelOptions.UpliftVan} }; return translationTable[mStabModelType]; } #endregion #region GridOrientation /// Converts to MStabGridPosition. /// The grid orientation. /// public static MStabGridPosition ConvertToMStabGridPosition(GridOrientation gridOrientation) { var translationTable = new Dictionary() { {GridOrientation.Inwards, MStabGridPosition.Right}, {GridOrientation.Outwards, MStabGridPosition.Left} }; return translationTable[gridOrientation]; } /// Converts to GridOrientation. /// The MStabGridPosition. /// public static GridOrientation ConvertToGridOrientation(MStabGridPosition mStabGridPosition) { var translationTable = new Dictionary() { {MStabGridPosition.Right, GridOrientation.Inwards}, {MStabGridPosition.Left, GridOrientation.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 = 0.0, // TODO find the correct parameter RatioCuPc = soil.RatioCuPc, RheologicalCoefficient = 0.0, // TODO find the correct parameter StrengthIncreaseExponent = 0.0, // TODO find the correct parameter UseSoilType = true, // TODO find the correct parameter BondStressCurve = null // TODO find the correct parameter }; if (soil.ShearStrengthModel != null) { macroStabilitySoil.ShearStrengthModel = ConvertToMacroStabilityShearStrengthModel(soil.ShearStrengthModel.Value); } else { macroStabilitySoil.ShearStrengthModel = MacroStability.Geometry.ShearStrengthModel.None; } switch (soil.DilatancyType) { case DilatancyType.MinusPhi: macroStabilitySoil.Dilatancy = -macroStabilitySoil.FrictionAngle; // -Phi (FrictionAngle) break; case DilatancyType.Phi: macroStabilitySoil.Dilatancy = macroStabilitySoil.FrictionAngle; // Phi (FrictionAngle) break; case DilatancyType.Zero: macroStabilitySoil.Dilatancy = 0.0; // Zero 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 = 1.01 RatioCuPc = soil.RatioCuPc, // RheologicalCoefficient = 1.07, ShearStrengthModel = ConvertToDamShearStrengthModel(soil.ShearStrengthModel), // StrengthIncreaseExponent = 1.08, // UseSoilType = true, // Following parameters are not available in MacroStability soil and will not be translated //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(MacroStability.Geometry.ShearStrengthModel kernelShearStrengthModel) { var translationTable = new Dictionary() { {MacroStability.Geometry.ShearStrengthModel.CPhi, ShearStrengthModel.CPhi}, {MacroStability.Geometry.ShearStrengthModel.CPhiOrCuCalculated, ShearStrengthModel.CPhiOrSuCalculated}, {MacroStability.Geometry.ShearStrengthModel.CuCalculated, ShearStrengthModel.SuCalculated}, {MacroStability.Geometry.ShearStrengthModel.CuGradient, ShearStrengthModel.SuGradient}, {MacroStability.Geometry.ShearStrengthModel.CuMeasured, ShearStrengthModel.SuMeasured}, {MacroStability.Geometry.ShearStrengthModel.None, ShearStrengthModel.None}, {MacroStability.Geometry.ShearStrengthModel.PseudoValues, ShearStrengthModel.PseudoValues}, {MacroStability.Geometry.ShearStrengthModel.StressTable, ShearStrengthModel.StressTable}, }; return translationTable[kernelShearStrengthModel]; } /// Converts to macro stability ShearStrengthModel. /// The dam ShearStrengthModel. /// /// public static MacroStability.Geometry.ShearStrengthModel ConvertToMacroStabilityShearStrengthModel(ShearStrengthModel damShearStrengthModel) { if (damShearStrengthModel == ShearStrengthModel.SuCalculatedWithYield) { throw new ArgumentException(string.Format("Cannot convert dam ShearStrengthModel: {0}", damShearStrengthModel)); } var translationTable = new Dictionary() { {ShearStrengthModel.CPhi, MacroStability.Geometry.ShearStrengthModel.CPhi}, {ShearStrengthModel.CPhiOrSuCalculated, MacroStability.Geometry.ShearStrengthModel.CPhiOrCuCalculated}, {ShearStrengthModel.None, MacroStability.Geometry.ShearStrengthModel.None}, {ShearStrengthModel.PseudoValues, MacroStability.Geometry.ShearStrengthModel.PseudoValues}, {ShearStrengthModel.StressTable, MacroStability.Geometry.ShearStrengthModel.StressTable}, {ShearStrengthModel.SuCalculated, MacroStability.Geometry.ShearStrengthModel.CuCalculated}, {ShearStrengthModel.SuGradient, MacroStability.Geometry.ShearStrengthModel.CuGradient}, {ShearStrengthModel.SuMeasured, MacroStability.Geometry.ShearStrengthModel.CuMeasured}, }; return translationTable[damShearStrengthModel]; } #endregion #region WaterpressureInterpolationModel /// Converts to macro stability waterpressure interpolation model. /// The waterpressure interpolation model. /// public static WaterpressureInterpolationModel ConvertToMacroStabilityWaterpressureInterpolationModel(Data.Geotechnics.WaterpressureInterpolationModel waterpressureInterpolationModel) { var translationTable = new Dictionary() { {Data.Geotechnics.WaterpressureInterpolationModel.Automatic, WaterpressureInterpolationModel.Automatic}, {Data.Geotechnics.WaterpressureInterpolationModel.Hydrostatic, WaterpressureInterpolationModel.Hydrostatic} }; return translationTable[waterpressureInterpolationModel]; } /// Converts to dam waterpressure interpolation model. /// The waterpressure interpolation model. /// public static Data.Geotechnics.WaterpressureInterpolationModel ConvertToDamWaterpressureInterpolationModel(WaterpressureInterpolationModel waterpressureInterpolationModel) { var translationTable = new Dictionary() { {WaterpressureInterpolationModel.Automatic, Data.Geotechnics.WaterpressureInterpolationModel.Automatic}, {WaterpressureInterpolationModel.Hydrostatic, Data.Geotechnics.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(MacroStability.Geometry.CharacteristicPointType kernelCharacteristicPointType) { var translationTable = new Dictionary() { {MacroStability.Geometry.CharacteristicPointType.BottomDitchDikeSide, CharacteristicPointType.BottomDitchDikeSide}, {MacroStability.Geometry.CharacteristicPointType.BottomDitchPolderSide, CharacteristicPointType.BottomDitchPolderSide}, {MacroStability.Geometry.CharacteristicPointType.DikeLine, CharacteristicPointType.DikeLine}, {MacroStability.Geometry.CharacteristicPointType.DikeToeAtPolder, CharacteristicPointType.DikeToeAtPolder}, {MacroStability.Geometry.CharacteristicPointType.DikeToeAtRiver, CharacteristicPointType.DikeToeAtRiver}, {MacroStability.Geometry.CharacteristicPointType.DikeTopAtPolder, CharacteristicPointType.DikeTopAtPolder}, {MacroStability.Geometry.CharacteristicPointType.DikeTopAtRiver, CharacteristicPointType.DikeTopAtRiver}, {MacroStability.Geometry.CharacteristicPointType.DitchDikeSide, CharacteristicPointType.DitchDikeSide}, {MacroStability.Geometry.CharacteristicPointType.DitchPolderSide, CharacteristicPointType.DitchPolderSide}, {MacroStability.Geometry.CharacteristicPointType.None, CharacteristicPointType.None}, {MacroStability.Geometry.CharacteristicPointType.ShoulderBaseInside, CharacteristicPointType.ShoulderBaseInside}, {MacroStability.Geometry.CharacteristicPointType.ShoulderBaseOutside, CharacteristicPointType.ShoulderBaseOutside}, {MacroStability.Geometry.CharacteristicPointType.ShoulderTopInside, CharacteristicPointType.ShoulderTopInside}, {MacroStability.Geometry.CharacteristicPointType.ShoulderTopOutside, CharacteristicPointType.ShoulderTopOutside}, {MacroStability.Geometry.CharacteristicPointType.SurfaceLevelInside, CharacteristicPointType.SurfaceLevelInside}, {MacroStability.Geometry.CharacteristicPointType.SurfaceLevelOutside, CharacteristicPointType.SurfaceLevelOutside}, {MacroStability.Geometry.CharacteristicPointType.TrafficLoadInside, CharacteristicPointType.TrafficLoadInside}, {MacroStability.Geometry.CharacteristicPointType.TrafficLoadOutside, CharacteristicPointType.TrafficLoadOutside} }; return translationTable[kernelCharacteristicPointType]; } /// Converts the type of to macro stability characteristic point. /// Type of the dam characteristic point. /// public static MacroStability.Geometry.CharacteristicPointType ConvertToMacroStabilityCharacteristicPointType(CharacteristicPointType damCharacteristicPointType) { var translationTable = new Dictionary() { {CharacteristicPointType.BottomDitchPolderSide, MacroStability.Geometry.CharacteristicPointType.BottomDitchPolderSide}, {CharacteristicPointType.BottomDitchDikeSide, MacroStability.Geometry.CharacteristicPointType.BottomDitchDikeSide}, {CharacteristicPointType.DikeLine, MacroStability.Geometry.CharacteristicPointType.DikeLine}, {CharacteristicPointType.DikeToeAtPolder, MacroStability.Geometry.CharacteristicPointType.DikeToeAtPolder}, {CharacteristicPointType.DikeToeAtRiver, MacroStability.Geometry.CharacteristicPointType.DikeToeAtRiver}, {CharacteristicPointType.DikeTopAtPolder, MacroStability.Geometry.CharacteristicPointType.DikeTopAtPolder}, {CharacteristicPointType.DikeTopAtRiver, MacroStability.Geometry.CharacteristicPointType.DikeTopAtRiver}, {CharacteristicPointType.DitchDikeSide, MacroStability.Geometry.CharacteristicPointType.DitchDikeSide}, {CharacteristicPointType.DitchPolderSide, MacroStability.Geometry.CharacteristicPointType.DitchPolderSide}, {CharacteristicPointType.None, MacroStability.Geometry.CharacteristicPointType.None}, {CharacteristicPointType.ShoulderBaseInside, MacroStability.Geometry.CharacteristicPointType.ShoulderBaseInside}, {CharacteristicPointType.ShoulderBaseOutside, MacroStability.Geometry.CharacteristicPointType.ShoulderBaseOutside}, {CharacteristicPointType.ShoulderTopInside, MacroStability.Geometry.CharacteristicPointType.ShoulderTopInside}, {CharacteristicPointType.ShoulderTopOutside, MacroStability.Geometry.CharacteristicPointType.ShoulderTopOutside}, {CharacteristicPointType.SurfaceLevelInside, MacroStability.Geometry.CharacteristicPointType.SurfaceLevelInside}, {CharacteristicPointType.SurfaceLevelOutside, MacroStability.Geometry.CharacteristicPointType.SurfaceLevelOutside}, {CharacteristicPointType.TrafficLoadInside, MacroStability.Geometry.CharacteristicPointType.TrafficLoadInside}, {CharacteristicPointType.TrafficLoadOutside, MacroStability.Geometry.CharacteristicPointType.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 LogMessageType ConvertKernelValidationResultTypeToLogMessageType(ValidationResultType messageType) { var translationTable = new Dictionary() { {ValidationResultType.Info, LogMessageType.Info}, {ValidationResultType.Warning, LogMessageType.Warning}, {ValidationResultType.Error, LogMessageType.Error} }; return translationTable[messageType]; } /// /// Converts the kernel log message type to log message type of DamEngine. /// /// Type of the message. /// public static LogMessageType ConvertKernelLogMessageTypeToLogMessageType(MacroStability.Standard.LogMessageType messageType) { var translationTable = new Dictionary() { {MacroStability.Standard.LogMessageType.Info, LogMessageType.Info}, {MacroStability.Standard.LogMessageType.Warning, LogMessageType.Warning}, {MacroStability.Standard.LogMessageType.Error, LogMessageType.Error} }; return translationTable[messageType]; } #endregion } }