// 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 Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.SoilProfile; using Ringtoets.MacroStabilityInwards.IO.Properties; using Ringtoets.MacroStabilityInwards.Primitives; using RingtoetsCommonResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.IO.SoilProfiles { /// /// Transforms generic into /// or . /// internal static class MacroStabilityInwardsSoilLayerTransformer { /// /// Transforms the generic into a /// . /// /// The soil layer to use in the transformation. /// A based on the given data. /// Thrown when is /// null. /// Thrown when transformation would not result /// in a valid transformed instance. public static MacroStabilityInwardsSoilLayer1D Transform(SoilLayer1D soilLayer) { if (soilLayer == null) { throw new ArgumentNullException(nameof(soilLayer)); } ValidateStochasticParameters(soilLayer); var layer = new MacroStabilityInwardsSoilLayer1D(soilLayer.Top) { Properties = { MaterialName = soilLayer.MaterialName, IsAquifer = soilLayer.IsAquifer, Color = soilLayer.Color, UsePop = soilLayer.UsePop, AbovePhreaticLevelMean = soilLayer.AbovePhreaticLevelMean, AbovePhreaticLevelDeviation = soilLayer.AbovePhreaticLevelDeviation, BelowPhreaticLevelMean = soilLayer.BelowPhreaticLevelMean, BelowPhreaticLevelDeviation = soilLayer.BelowPhreaticLevelDeviation, CohesionMean = soilLayer.CohesionMean, CohesionDeviation = soilLayer.CohesionDeviation, FrictionAngleMean = soilLayer.FrictionAngleMean, FrictionAngleDeviation = soilLayer.FrictionAngleDeviation, ShearStrengthRatioMean = soilLayer.ShearStrengthRatioMean, ShearStrengthRatioDeviation = soilLayer.ShearStrengthRatioDeviation, StrengthIncreaseExponentMean = soilLayer.StrengthIncreaseExponentMean, StrengthIncreaseExponentDeviation = soilLayer.StrengthIncreaseExponentDeviation, PopMean = soilLayer.PopMean, PopDeviation = soilLayer.PopDeviation } }; try { layer.Properties.ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel); } catch (NotSupportedException e) { throw new ImportedDataTransformException("Er ging iets mis met transformeren.", e); } return layer; } /// /// Validates whether the values of the distribution and shift for the stochastic parameters /// are correct for creating a soil layer. /// /// Thrown when any of the distributions of the /// stochastic parameters is not defined as lognormal or is shifted when it should not be. private static void ValidateStochasticParameters(SoilLayerBase soilLayer) { ValidateIsNonShiftedLogNormal( soilLayer.CohesionDistribution, soilLayer.CohesionShift, Resources.SoilLayerProperties_CohesionDistribution_Description); ValidateIsNonShiftedLogNormal( soilLayer.FrictionAngleDistribution, soilLayer.FrictionAngleShift, Resources.SoilLayerProperties_FrictionAngleDistribution_Description); ValidateIsNonShiftedLogNormal( soilLayer.ShearStrengthRatioDistribution, soilLayer.ShearStrengthRatioShift, Resources.SoilLayerProperties_ShearStrengthRatioDistribution_Description); ValidateIsNonShiftedLogNormal( soilLayer.StrengthIncreaseExponentDistribution, soilLayer.StrengthIncreaseExponentShift, Resources.SoilLayerProperties_StrengthIncreaseExponentDistribution_Description); ValidateIsNonShiftedLogNormal( soilLayer.PopDistribution, soilLayer.PopShift, Resources.SoilLayerProperties_PopDistribution_Description); } private static void ValidateIsNonShiftedLogNormal(long? distribution, double shift, string incorrectDistibutionParameter) { if (distribution.HasValue && (distribution.Value != SoilLayerConstants.LogNormalDistributionValue || Math.Abs(shift) > 1e-6)) { throw new ImportedDataTransformException(string.Format( RingtoetsCommonResources.SoilLayer_Stochastic_parameter_0_has_no_lognormal_distribution, incorrectDistibutionParameter)); } } /// /// Transforms the to . /// /// The model to transform. /// A based on the given data. /// Thrown when /// has an invalid value. private static MacroStabilityInwardsShearStrengthModel TransformShearStrengthModel(ShearStrengthModel shearStrengthModel) { switch (shearStrengthModel) { case ShearStrengthModel.None: return MacroStabilityInwardsShearStrengthModel.None; case ShearStrengthModel.SuCalculated: return MacroStabilityInwardsShearStrengthModel.SuCalculated; case ShearStrengthModel.CPhi: return MacroStabilityInwardsShearStrengthModel.CPhi; case ShearStrengthModel.CPhiOrSuCalculated: return MacroStabilityInwardsShearStrengthModel.CPhiOrSuCalculated; default: throw new NotSupportedException(); } } } }