// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU 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.ComponentModel;
using System.Linq;
using Deltares.WTIStability.Data.Geo;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan;
using DilatancyType = Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Input.DilatancyType;
using ShearStrengthModel = Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Input.ShearStrengthModel;
using SoilProfile = Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Input.SoilProfile;
using WTIStabilityDilatancyType = Deltares.WTIStability.Data.Geo.DilatancyType;
using WTIStabilityShearStrengthModel = Deltares.WTIStability.Data.Geo.ShearStrengthModel;
namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Creators.Input
{
///
/// Creates instances which are required by .
///
internal static class SoilCreator
{
///
/// Creates a based on information contained in the profile ,
/// which can be used by .
///
/// The from which to take the information.
/// A new with information taken from the .
/// Thrown when is null.
/// Thrown when
/// or is an invalid value.
/// Thrown when
/// or is a valid value but unsupported.
public static Soil[] Create(SoilProfile profile)
{
if (profile == null)
{
throw new ArgumentNullException(nameof(profile));
}
return profile.Layers.Select(l => new Soil(l.MaterialName)
{
UsePop = l.UsePop,
ShearStrengthModel = ConvertShearStrengthModel(l.ShearStrengthModel),
AbovePhreaticLevel = l.AbovePhreaticLevel,
BelowPhreaticLevel = l.BelowPhreaticLevel,
Cohesion = l.Cohesion,
FrictionAngle = l.FrictionAngle,
RatioCuPc = l.ShearStrengthRatio,
StrengthIncreaseExponent = l.StrengthIncreaseExponent,
PoP = l.Pop,
DilatancyType = ConvertDilatancyType(l.DilatancyType)
}).ToArray();
}
///
/// Converts a into a .
///
/// The to convert.
/// A based on .
/// Thrown when
/// is an invalid value.
/// Thrown when
/// is a valid value but unsupported.
private static WTIStabilityShearStrengthModel ConvertShearStrengthModel(ShearStrengthModel shearStrengthModel)
{
if (!Enum.IsDefined(typeof(ShearStrengthModel), shearStrengthModel))
{
throw new InvalidEnumArgumentException(nameof(shearStrengthModel),
(int) shearStrengthModel,
typeof(ShearStrengthModel));
}
switch (shearStrengthModel)
{
case ShearStrengthModel.SuCalculated:
return WTIStabilityShearStrengthModel.CuCalculated;
case ShearStrengthModel.CPhi:
return WTIStabilityShearStrengthModel.CPhi;
case ShearStrengthModel.CPhiOrSuCalculated:
return WTIStabilityShearStrengthModel.CPhiOrCuCalculated;
default:
throw new NotSupportedException();
}
}
///
/// Converts a into a .
///
/// The to convert.
/// A based on .
/// Thrown when
/// is an invalid value.
/// Thrown when
/// is a valid value but unsupported.
private static WTIStabilityDilatancyType ConvertDilatancyType(DilatancyType dilatancyType)
{
if (!Enum.IsDefined(typeof(DilatancyType), dilatancyType))
{
throw new InvalidEnumArgumentException(nameof(dilatancyType),
(int) dilatancyType,
typeof(DilatancyType));
}
switch (dilatancyType)
{
case DilatancyType.Phi:
return WTIStabilityDilatancyType.Phi;
case DilatancyType.Zero:
return WTIStabilityDilatancyType.Zero;
case DilatancyType.MinusPhi:
return WTIStabilityDilatancyType.MinusPhi;
default:
throw new NotSupportedException();
}
}
}
}