// 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.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Core.Common.Base.Geometry;
using Ringtoets.Common.Data.Helpers;
using Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Input;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Ringtoets.MacroStabilityInwards.CalculatedInput.Converters
{
///
/// Converter to convert
/// into .
///
public static class SoilProfileConverter
{
///
/// Converts
/// into .
///
/// The soil profile to convert.
/// The converted .
/// Thrown when
/// is null.
/// Thrown when
///
/// is an invalid value.
/// Thrown when
///
/// is a valid value but unsupported.
public static SoilProfile Convert(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile)
{
if (soilProfile == null)
{
throw new ArgumentNullException(nameof(soilProfile));
}
IEnumerable layers = ConvertLayers(soilProfile.Layers);
IEnumerable preconsolidationStresses = ConvertPreconsolidationStresses(soilProfile.PreconsolidationStresses);
return new SoilProfile(layers, preconsolidationStresses);
}
///
/// Converts objects into objects.
///
/// The layers to convert.
/// The converted .
/// Thrown when
///
/// is an invalid value.
/// Thrown when
///
/// is a valid value but unsupported.
private static IEnumerable ConvertLayers(IEnumerable layers)
{
return layers.Select(l =>
{
MacroStabilityInwardsSoilLayerData data = l.Data;
return new SoilLayer(RingToPoints(l.OuterRing),
new SoilLayer.ConstructionProperties
{
MaterialName = SoilLayerDataHelper.GetValidName(data.MaterialName),
UsePop = data.UsePop,
IsAquifer = data.IsAquifer,
ShearStrengthModel = ConvertShearStrengthModel(data.ShearStrengthModel),
AbovePhreaticLevel = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(data).GetDesignValue(),
BelowPhreaticLevel = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(data).GetDesignValue(),
Cohesion = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(data).GetDesignValue(),
FrictionAngle = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(data).GetDesignValue(),
ShearStrengthRatio = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(data).GetDesignValue(),
StrengthIncreaseExponent = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(data).GetDesignValue(),
Pop = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPop(data).GetDesignValue(),
DilatancyType = DilatancyType.Zero,
WaterPressureInterpolationModel = WaterPressureInterpolationModel.Automatic
},
ConvertLayers(l.NestedLayers));
}).ToArray();
}
private static Point2D[] RingToPoints(Ring ring)
{
return ring.Points.ToArray();
}
private static IEnumerable ConvertPreconsolidationStresses(
IEnumerable preconsolidationStresses)
{
return preconsolidationStresses.Select(ps => new PreconsolidationStress(
ps.Location,
MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPreconsolidationStress(ps).GetDesignValue()));
}
///
/// Converts a to a .
///
/// The to convert.
/// A based on the information of .
/// Thrown when
/// is an invalid value.
/// Thrown when
/// is a valid value but unsupported.
private static ShearStrengthModel ConvertShearStrengthModel(MacroStabilityInwardsShearStrengthModel shearStrengthModel)
{
if (!Enum.IsDefined(typeof(MacroStabilityInwardsShearStrengthModel), shearStrengthModel))
{
throw new InvalidEnumArgumentException(nameof(shearStrengthModel),
(int) shearStrengthModel,
typeof(MacroStabilityInwardsShearStrengthModel));
}
switch (shearStrengthModel)
{
case MacroStabilityInwardsShearStrengthModel.SuCalculated:
return ShearStrengthModel.SuCalculated;
case MacroStabilityInwardsShearStrengthModel.CPhi:
return ShearStrengthModel.CPhi;
case MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated:
return ShearStrengthModel.CPhiOrSuCalculated;
default:
throw new NotSupportedException();
}
}
}
}