// 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.MacroStability.Data; using Deltares.MacroStability.Geometry; 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) { var translationTable = new Dictionary() { {ModelOptions.Bishop, MStabModelType.Bishop}, {ModelOptions.BishopProbabilityRandomField, MStabModelType.BishopRandomField}, {ModelOptions.Fellenius, MStabModelType.Fellenius}, {ModelOptions.HorizontalBalance, MStabModelType.HorizontalBalance}, {ModelOptions.Spencer, MStabModelType.Spencer}, {ModelOptions.UpliftSpencer, MStabModelType.UpliftSpencer}, {ModelOptions.UpliftVan, MStabModelType.UpliftVan} }; return translationTable[modelOption]; } /// Converts to ModelOptions type. /// the MStabModelType. /// the MacroStability ModelOption /// public static ModelOptions ConvertToModelOptions(MStabModelType mStabModelType) { if (mStabModelType == MStabModelType.SpencerHigh || mStabModelType == MStabModelType.SpencerLow) { throw new ArgumentException(String.Format("Unsupported MStabModelType: {0}", mStabModelType)); } var translationTable = new Dictionary() { {MStabModelType.Bishop, ModelOptions.Bishop}, {MStabModelType.BishopRandomField, ModelOptions.BishopProbabilityRandomField}, {MStabModelType.Fellenius, ModelOptions.Fellenius}, {MStabModelType.HorizontalBalance, ModelOptions.HorizontalBalance}, {MStabModelType.Spencer, ModelOptions.Spencer}, {MStabModelType.UpliftSpencer, ModelOptions.UpliftSpencer}, {MStabModelType.UpliftVan, 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 } }