// 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;
using Deltares.MacroStability.Data;
using Deltares.MacroStability.Geometry;
using Soil = Deltares.MacroStability.Geometry.Soil;
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
#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
};
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,
// 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,
//ShearStrengthModel = ShearStrengthModel.CPhi,
//SlopeRestProfile = 0.00,
//SoilType = SoilType.Clay,
//UseDefaultShearStrengthModel = false,
//UsePop = true,
//WhitesConstant = 0.00,
};
if (soil.Dilatancy.AlmostEquals(soil.FrictionAngle, tolerance))
{
damSoil.DilatancyType = DilatancyType.Phi;
}
else if (soil.Dilatancy.AlmostEquals(-soil.FrictionAngle, tolerance))
{
damSoil.DilatancyType = DilatancyType.MinusPhi;
}
else if (soil.Dilatancy.AlmostEquals(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;
}
#endregion
}
}