Index: src/Deltares.DSoilModel.Data/DSoilModelTransformer.cs
===================================================================
diff -u -r6 -r99
--- src/Deltares.DSoilModel.Data/DSoilModelTransformer.cs (.../DSoilModelTransformer.cs) (revision 6)
+++ src/Deltares.DSoilModel.Data/DSoilModelTransformer.cs (.../DSoilModelTransformer.cs) (revision 99)
@@ -4,19 +4,21 @@
namespace Deltares.DSoilModel.Data
{
+ ///
+ /// Conversion between measured and design values for DSoilModel
+ /// note: in DSoilModel the default transformation of design values is replaced by ActualValue field of Stochast
+ ///
+ ///
public class DSoilModelTransformer : ITransformer
{
public double GetTransformedValue(object owner, string property, double measuredValue)
{
if (owner is Soil)
{
- var stochasts = ((Soil)owner).GetStochasts();
- foreach (var stochast in stochasts)
+ var stochast = ((Soil)owner).GetStochast(property);
+ if (stochast != null)
{
- if (stochast.AssociatedPropertyName == property)
- {
- return stochast.ActualValue;
- }
+ return stochast.ActualValue;
}
}
return measuredValue;
@@ -26,16 +28,13 @@
{
if (owner is Soil)
{
- var stochasts = ((Soil)owner).GetStochasts();
- foreach (var stochast in stochasts)
+ var stochast = ((Soil)owner).GetStochast(property);
+ if (stochast != null)
{
- if (stochast.AssociatedPropertyName == property)
- {
- stochast.ActualValue = transformedValue;
+ stochast.ActualValue = transformedValue;
- // In property setter, the return value of this method is used to set the stochast mean
- return stochast.Mean;
- }
+ // In property setter, the return value of this method is used to set the stochast mean
+ return stochast.Mean;
}
}
return transformedValue;
Index: src/Deltares.DSoilModel.Tests/DSoilModelTransformerTest.cs
===================================================================
diff -u
--- src/Deltares.DSoilModel.Tests/DSoilModelTransformerTest.cs (revision 0)
+++ src/Deltares.DSoilModel.Tests/DSoilModelTransformerTest.cs (revision 99)
@@ -0,0 +1,76 @@
+using System;
+using System.Security.Cryptography.X509Certificates;
+using System.Windows.Forms;
+using Deltares.DSoilModel.Data;
+using Deltares.Geotechnics;
+using Deltares.Probabilistic;
+using Deltares.Standard;
+using Deltares.Standard.Reflection;
+using NUnit.Framework;
+
+namespace Deltares.DSoilModel.Tests
+{
+ [TestFixture]
+ public class DSoilModelTransformerTest
+ {
+ private ITransformer oldTransformer;
+ private bool oldReliability;
+
+ [SetUp]
+ public void Setup()
+ {
+ oldTransformer = TransformerManager.Transformer;
+ oldReliability = ReliabilityView.IsReliability;
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ TransformerManager.Transformer = oldTransformer;
+ ReliabilityView.IsReliability = oldReliability;
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public void TransformerMapsSoilPropertiesToActualValues(bool reliability)
+ {
+ ReliabilityView.IsReliability = reliability;
+
+ var transformer = new DSoilModelTransformer();
+ TransformerManager.Transformer = transformer;
+
+ var soil = new Soil();
+ var stochastProperties = PropertyInfoSupport.GetPropertiesOfType(typeof(Soil), typeof(Stochast));
+
+ foreach (BindPropertyInfo stochastPropertyInfo in stochastProperties)
+ {
+ var stochast = (Stochast)stochastPropertyInfo.GetValue(soil, null);
+ stochast.ActualValue = 1.23;
+ stochast.Mean = double.NaN;
+
+ // call transformer directly, always returns ActualValue, ignoring measuredValue input
+ Assert.AreEqual(1.23, transformer.GetTransformedValue(soil, stochast.AssociatedPropertyName, 9999));
+
+ // check associated property indeed returns ActualValue
+ var propertyInfo = typeof(Soil).GetProperty(stochast.AssociatedPropertyName);
+ var value = propertyInfo.GetValue(soil, null);
+ if (propertyInfo.PropertyType == typeof(double))
+ {
+ Assert.AreEqual(1.23, value);
+ }
+
+ // reverse transformation, directly
+ transformer.SetTransformedValue(soil, stochast.AssociatedPropertyName, 3.21);
+ Assert.AreEqual(3.21, stochast.ActualValue);
+
+ // reverse via associated property
+ if (propertyInfo.PropertyType == typeof(double))
+ {
+ propertyInfo.SetValue(soil, 9.87, null);
+ Assert.AreEqual(9.87, stochast.ActualValue);
+ }
+ }
+ }
+ }
+}