Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs
===================================================================
diff -u -r868b45ff456a9f30061487dacfe75d003b3a9e4e -r002a45b294481f03e3d7a9eb7469f5fae367e39b
--- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 868b45ff456a9f30061487dacfe75d003b3a9e4e)
+++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.IO/SoilProfiles/MacroStabilityInwardsSoilLayerTransformer.cs (.../MacroStabilityInwardsSoilLayerTransformer.cs) (revision 002a45b294481f03e3d7a9eb7469f5fae367e39b)
@@ -106,57 +106,107 @@
/// in a valid transformed instance.
private static MacroStabilityInwardsSoilLayerData ConvertSoilLayerData(SoilLayerBase soilLayer)
{
- string soilLayerMaterialName = soilLayer.MaterialName;
+ string soilLayerName = soilLayer.MaterialName;
return new MacroStabilityInwardsSoilLayerData
{
- ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel, soilLayerMaterialName),
- UsePop = TransformUsePop(soilLayer.UsePop, soilLayerMaterialName),
+ ShearStrengthModel = TransformShearStrengthModel(soilLayer.ShearStrengthModel, soilLayerName),
+ UsePop = TransformUsePop(soilLayer.UsePop, soilLayerName),
- MaterialName = soilLayerMaterialName,
- IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayerMaterialName),
+ MaterialName = soilLayerName,
+ IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayerName),
Color = SoilLayerColorConverter.Convert(soilLayer.Color),
- AbovePhreaticLevel = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.AbovePhreaticLevelMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.AbovePhreaticLevelCoefficientOfVariation,
- Shift = (RoundedDouble) soilLayer.AbovePhreaticLevelShift
- },
- BelowPhreaticLevel = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.BelowPhreaticLevelMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.BelowPhreaticLevelCoefficientOfVariation,
- Shift = (RoundedDouble) soilLayer.BelowPhreaticLevelShift
- },
- Cohesion = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.CohesionMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.CohesionCoefficientOfVariation
- },
- FrictionAngle = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.FrictionAngleMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.FrictionAngleCoefficientOfVariation
- },
- ShearStrengthRatio = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.ShearStrengthRatioMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.ShearStrengthRatioCoefficientOfVariation
- },
- StrengthIncreaseExponent = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.StrengthIncreaseExponentMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.StrengthIncreaseExponentCoefficientOfVariation
- },
- Pop = new VariationCoefficientLogNormalDistribution
- {
- Mean = (RoundedDouble) soilLayer.PopMean,
- CoefficientOfVariation = (RoundedDouble) soilLayer.PopCoefficientOfVariation
- }
+ AbovePhreaticLevel = TransformLogNormalDistribution(soilLayer.AbovePhreaticLevelMean,
+ soilLayer.AbovePhreaticLevelCoefficientOfVariation,
+ soilLayer.AbovePhreaticLevelShift,
+ soilLayerName,
+ "Onverzadigd gewicht"),
+ BelowPhreaticLevel = TransformLogNormalDistribution(soilLayer.BelowPhreaticLevelMean,
+ soilLayer.BelowPhreaticLevelCoefficientOfVariation,
+ soilLayer.BelowPhreaticLevelShift,
+ soilLayerName,
+ "Verzadigd gewicht"),
+
+ Cohesion = TransformLogNormalDistribution(soilLayer.CohesionMean,
+ soilLayer.CohesionCoefficientOfVariation,
+ soilLayerName,
+ "Cohesie"),
+ FrictionAngle = TransformLogNormalDistribution(soilLayer.FrictionAngleMean,
+ soilLayer.FrictionAngleCoefficientOfVariation,
+ soilLayerName,
+ "Wrijvingshoek"),
+ ShearStrengthRatio = TransformLogNormalDistribution(soilLayer.ShearStrengthRatioMean,
+ soilLayer.ShearStrengthRatioCoefficientOfVariation,
+ soilLayerName,
+ "Schuifsterkte ratio (S)"),
+ StrengthIncreaseExponent = TransformLogNormalDistribution(soilLayer.StrengthIncreaseExponentMean,
+ soilLayer.StrengthIncreaseExponentCoefficientOfVariation,
+ soilLayerName,
+ "Sterkte toename exp (m)"),
+ Pop = TransformLogNormalDistribution(soilLayer.PopMean,
+ soilLayer.PopCoefficientOfVariation,
+ soilLayerName,
+ "POP")
};
}
///
+ /// Transforms the input arguments into a log normal distribution for a parameter of a soil layer.
+ ///
+ /// The mean of the distribution.
+ /// The coefficient of variation of the distribution.
+ /// The name of the soil layer.
+ /// The name of the parameter to create a distribution for.
+ /// A based on the input arguments.
+ ///
+ private static VariationCoefficientLogNormalDistribution TransformLogNormalDistribution(double mean,
+ double coefficientOfVariation,
+ string soilLayerName,
+ string parameterName)
+ {
+ return TransformLogNormalDistribution(mean,
+ coefficientOfVariation,
+ new VariationCoefficientLogNormalDistribution().Shift,
+ soilLayerName,
+ parameterName);
+ }
+
+ ///
+ /// Transforms the input arguments into a log normal distribution for a parameter of a soil layer.
+ ///
+ /// The mean of the distribution.
+ /// The coefficient of variation of the distribution.
+ /// The shift of the distribution.
+ /// The name of the soil layer.
+ /// The name of the parameter to create a distribution for.
+ /// A based on the input arguments.
+ ///
+ private static VariationCoefficientLogNormalDistribution TransformLogNormalDistribution(double mean,
+ double coefficientOfVariation,
+ double shift,
+ string soilLayerName,
+ string parameterName)
+ {
+ try
+ {
+ return new VariationCoefficientLogNormalDistribution
+ {
+ Mean = (RoundedDouble) mean,
+ CoefficientOfVariation = (RoundedDouble) coefficientOfVariation,
+ Shift = (RoundedDouble) shift
+ };
+ }
+ catch (ArgumentOutOfRangeException e)
+ {
+ string exceptionMessage = string.Format("Er is een fout opgetreden bij het inlezen van grondlaag '{0}' voor parameter '{1}': {2}",
+ soilLayerName,
+ parameterName,
+ e.Message);
+ throw new ImportedDataTransformException(exceptionMessage, e);
+ }
+ }
+
+ ///
/// Transforms a to a for the
/// is aquifer property of soil layers.
///
@@ -175,7 +225,7 @@
{
string exceptionMessage = CreateErrorMessage(soilLayerName,
string.Format(RingtoetsCommonIOResources.Transform_Invalid_value_ParameterName_0,
- RingtoetsCommonIOResources.SoilLayerData_IsAquifer_DisplayName));
+ RingtoetsCommonIOResources.SoilLayerData_IsAquifer_DisplayName));
throw new ImportedDataTransformException(exceptionMessage, e);
}
}
Index: Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs
===================================================================
diff -u -r868b45ff456a9f30061487dacfe75d003b3a9e4e -r002a45b294481f03e3d7a9eb7469f5fae367e39b
--- Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs (.../MacroStabilityInwardsSoilLayerTransformerTest.cs) (revision 868b45ff456a9f30061487dacfe75d003b3a9e4e)
+++ Ringtoets/MacroStabilityInwards/test/Ringtoets.MacroStabilityInwards.IO.Test/SoilProfiles/MacroStabilityInwardsSoilLayerTransformerTest.cs (.../MacroStabilityInwardsSoilLayerTransformerTest.cs) (revision 002a45b294481f03e3d7a9eb7469f5fae367e39b)
@@ -341,6 +341,22 @@
}
[Test]
+ [TestCaseSource(nameof(InvalidStochasticDistributionValuesSoilLayer1D))]
+ public void SoilLayer1DTransform_InvalidStochasticDistributionValues_ThrowImportedDataTransformException(SoilLayer1D layer, string parameter)
+ {
+ // Call
+ TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
+
+ // Assert
+ Exception exception = Assert.Throws(test);
+
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ string expectedMessage = $"Er is een fout opgetreden bij het inlezen van grondlaag '{layer.MaterialName}' voor parameter '{parameter}': {innerException.Message}";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
+ [Test]
public void SoilLayer2DTransform_SoilLayer2DNull_ThrowsArgumentNullException()
{
// Call
@@ -590,6 +606,22 @@
Assert.IsInstanceOf(exception.InnerException);
}
+ [Test]
+ [TestCaseSource(nameof(InvalidStochasticDistributionValuesSoilLayer2D))]
+ public void SoilLayer2DTransform_InvalidStochasticDistributionValues_ThrowImportedDataTransformException(SoilLayer2D layer, string parameter)
+ {
+ // Call
+ TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer);
+
+ // Assert
+ Exception exception = Assert.Throws(test);
+
+ Exception innerException = exception.InnerException;
+ Assert.IsInstanceOf(innerException);
+ string expectedMessage = $"Er is een fout opgetreden bij het inlezen van grondlaag '{layer.MaterialName}' voor parameter '{parameter}': {innerException.Message}";
+ Assert.AreEqual(expectedMessage, exception.Message);
+ }
+
private static SoilLayer2DLoop CreateRandomLoop(int seed)
{
var random = new Random(seed);
@@ -756,6 +788,65 @@
#endregion
+ #region Distribution properties
+
+ private static IEnumerable InvalidStochasticDistributionValuesSoilLayer1D()
+ {
+ return InvalidStochasticDistributionValues(() => SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer(), nameof(SoilLayer1D));
+ }
+
+ private static IEnumerable InvalidStochasticDistributionValuesSoilLayer2D()
+ {
+ return InvalidStochasticDistributionValues(SoilLayer2DTestFactory.CreateSoilLayer2D, nameof(SoilLayer2D));
+ }
+
+ private static IEnumerable InvalidStochasticDistributionValues(Func soilLayer, string typeName)
+ {
+ const string testNameFormat = "{0}Transform_InvalidStochasticDistributionValues{{1}}_ThrowsImportedDataTransformException";
+ const double invalidMean = 0;
+
+ SoilLayerBase invalidCohesion = soilLayer();
+ invalidCohesion.CohesionMean = invalidMean;
+ yield return new TestCaseData(invalidCohesion, "Cohesie"
+ ).SetName(string.Format(testNameFormat, typeName));
+
+ SoilLayerBase invalidFrictionAngle = soilLayer();
+ invalidFrictionAngle.FrictionAngleMean = invalidMean;
+ yield return new TestCaseData(invalidFrictionAngle, "Wrijvingshoek"
+ ).SetName(string.Format(testNameFormat, typeName));
+
+ SoilLayerBase invalidShearStrengthRatio = soilLayer();
+ invalidShearStrengthRatio.ShearStrengthRatioMean = invalidMean;
+ yield return new TestCaseData(invalidShearStrengthRatio, "Schuifsterkte ratio (S)"
+ ).SetName(string.Format(testNameFormat, typeName));
+
+ SoilLayerBase invalidStrengthIncreaseExponent = soilLayer();
+ invalidStrengthIncreaseExponent.StrengthIncreaseExponentMean = invalidMean;
+ yield return new TestCaseData(invalidStrengthIncreaseExponent, "Sterkte toename exp (m)"
+ ).SetName(string.Format(testNameFormat, typeName));
+
+ SoilLayerBase invalidPop = soilLayer();
+ invalidPop.PopMean = invalidMean;
+ yield return new TestCaseData(invalidPop, "POP"
+ ).SetName(string.Format(testNameFormat, typeName));
+
+ const double validMean = 1;
+ const double invalidShift = 2;
+ SoilLayerBase invalidBelowPhreaticLevel = soilLayer();
+ invalidBelowPhreaticLevel.BelowPhreaticLevelMean = validMean;
+ invalidBelowPhreaticLevel.BelowPhreaticLevelShift = invalidShift;
+ yield return new TestCaseData(invalidBelowPhreaticLevel, "Verzadigd gewicht")
+ .SetName(string.Format(testNameFormat, typeName));
+
+ SoilLayerBase invalidAbovePhreaticLevel = soilLayer();
+ invalidAbovePhreaticLevel.AbovePhreaticLevelMean = validMean;
+ invalidAbovePhreaticLevel.AbovePhreaticLevelShift = invalidShift;
+ yield return new TestCaseData(invalidAbovePhreaticLevel, "Onverzadigd gewicht")
+ .SetName(string.Format(testNameFormat, typeName));
+ }
+
+ #endregion
+
#region Test Data: Shifted Log Normal Distributions
private static IEnumerable IncorrectShiftedLogNormalDistributionsSoilLayer1D()