/// <summary>
        /// Asserts whether <paramref name="actual"/> corresponds to <paramref name="original"/>.
        /// </summary>
        /// <param name="original">The original <see cref="MacroStabilityInwardsSoilLayer2D"/> array.</param>
        /// <param name="actual">The actual <see cref="SoilLayer"/> array.</param>
        /// <exception cref="AssertionException">Thrown when <paramref name="original"/>
        /// does not correspond to <paramref name="original"/>.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="original"/>
        /// contains an item with an invalid value of the enum <see cref="MacroStabilityInwardsShearStrengthModel"/>.</exception>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="original"/>
        /// contains an item with an unsupported value of <see cref="MacroStabilityInwardsShearStrengthModel"/>.</exception>
        private static void AssertLayers(MacroStabilityInwardsSoilLayer2D[] original, SoilLayer[] actual)
        {
            Assert.AreEqual(original.Length, actual.Length);

            for (var i = 0; i < original.Length; i++)
            {
                CollectionAssert.AreEqual(original[i].OuterRing.Points, actual[i].OuterRing);

                AssertLayers(original[i].NestedLayers.ToArray(), actual[i].NestedLayers.ToArray());

                MacroStabilityInwardsSoilLayerData expectedData = original[i].Data;
                Assert.AreEqual(expectedData.MaterialName, actual[i].MaterialName);
                Assert.AreEqual(expectedData.UsePop, actual[i].UsePop);
                Assert.AreEqual(expectedData.IsAquifer, actual[i].IsAquifer);
                Assert.AreEqual(0.0, actual[i].Dilatancy);
                Assert.AreEqual(WaterPressureInterpolationModel.Automatic, actual[i].WaterPressureInterpolationModel);
                Assert.AreEqual(ConvertShearStrengthModel(expectedData.ShearStrengthModel), actual[i].ShearStrengthModel);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(expectedData).GetDesignValue(), actual[i].AbovePhreaticLevel);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(expectedData).GetDesignValue(), actual[i].BelowPhreaticLevel);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(expectedData).GetDesignValue(), actual[i].Cohesion);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(expectedData).GetDesignValue(), actual[i].FrictionAngle);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(expectedData).GetDesignValue(), actual[i].StrengthIncreaseExponent);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(expectedData).GetDesignValue(), actual[i].ShearStrengthRatio);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPop(expectedData).GetDesignValue(), actual[i].Pop);
            }
        }
        /// <summary>
        /// Converts <see cref="MacroStabilityInwardsSoilLayer2D"/> objects into <see cref="SoilLayer"/> objects.
        /// </summary>
        /// <param name="layers">The layers to convert.</param>
        /// <returns>The converted <see cref="SoilLayer"/>.</returns>
        /// <exception cref="InvalidEnumArgumentException">Thrown when
        /// <see cref="MacroStabilityInwardsSoilLayerData.ShearStrengthModel"/>
        /// is an invalid value.</exception>
        /// <exception cref="NotSupportedException">Thrown when
        /// <see cref="MacroStabilityInwardsSoilLayerData.ShearStrengthModel"/>
        /// is a valid value, but unsupported.</exception>
        private static IEnumerable <SoilLayer> ConvertLayers(IEnumerable <MacroStabilityInwardsSoilLayer2D> 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(),
                    Dilatancy = 0.0,
                    WaterPressureInterpolationModel = WaterPressureInterpolationModel.Automatic
                },
                                     ConvertLayers(l.NestedLayers));
            }).ToArray());
        }
Exemple #3
0
        public void SetData_WithData_ExpectedValuesInTable()
        {
            // Setup
            using (var table = new MacroStabilityInwardsSoilLayerDataTable())
            {
                MacroStabilityInwardsSoilLayerData[] layers =
                {
                    CreateMacroStabilityInwardsSoilLayerData(),
                    CreateMacroStabilityInwardsSoilLayerData(),
                    CreateMacroStabilityInwardsSoilLayerData()
                };
                table.SetData(new[]
                {
                    new MacroStabilityInwardsSoilLayerData()
                });

                // Call
                table.SetData(layers);

                // Assert
                Assert.AreEqual(layers.Length, table.Rows.Count);
                for (var i = 0; i < table.Rows.Count; i++)
                {
                    MacroStabilityInwardsSoilLayerData soilLayerData = layers[i];
                    DataGridViewCellCollection         rowCells      = table.Rows[i].Cells;
                    Assert.AreEqual(soilLayerData.MaterialName,
                                    rowCells[nameColumnIndex].Value);
                    Assert.AreEqual(soilLayerData.Color,
                                    rowCells[colorColumnIndex].Value);
                    Assert.AreEqual(soilLayerData.IsAquifer,
                                    rowCells[isAquiferColumnIndex].Value);
                    AssertShiftedDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(soilLayerData),
                                                                rowCells[abovePhreaticLevelColumnIndex].Value);
                    AssertShiftedDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(soilLayerData),
                                                                rowCells[belowPhreaticLevelColumnIndex].Value);
                    Assert.AreEqual(soilLayerData.ShearStrengthModel,
                                    rowCells[shearStrengthModelColumnIndex].Value);
                    AssertDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(soilLayerData),
                                                         rowCells[cohesionColumnIndex].Value);
                    AssertDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(soilLayerData),
                                                         rowCells[frictionAngleColumnIndex].Value);
                    AssertDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(soilLayerData),
                                                         rowCells[shrearStrengthRatioColumnIndex].Value);
                    AssertDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(soilLayerData),
                                                         rowCells[strengthIncreaseExponentColumnIndex].Value);
                    Assert.AreEqual(soilLayerData.UsePop,
                                    rowCells[usePopColumnIndex].Value);
                    AssertDesignVariableColumnValueEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPop(soilLayerData),
                                                         rowCells[popColumnIndex].Value);
                }
            }
        }
        /// <summary>
        /// Asserts whether the <see cref="PersistableSoil"/> contains the data
        /// that is representative for the <paramref name="originalLayers"/>.
        /// </summary>
        /// <param name="originalLayers">The layers that contain the original data.</param>
        /// <param name="actualSoils">The collection of <see cref="PersistableSoil"/>
        /// that needs to be asserted.</param>
        /// <exception cref="AssertionException">Thrown when the data in <paramref name="actualSoils"/>
        /// is not correct.</exception>
        public static void AssertPersistableSoils(IEnumerable <IMacroStabilityInwardsSoilLayer> originalLayers, IEnumerable <PersistableSoil> actualSoils)
        {
            Assert.AreEqual(originalLayers.Count(), actualSoils.Count());

            for (var i = 0; i < originalLayers.Count(); i++)
            {
                PersistableSoil soil = actualSoils.ElementAt(i);
                MacroStabilityInwardsSoilLayerData layerData = originalLayers.ElementAt(i).Data;

                Assert.IsNotNull(soil.Id);
                Assert.AreEqual(layerData.MaterialName, soil.Name);
                Assert.AreEqual($"{layerData.MaterialName}-{soil.Id}", soil.Code);
                Assert.IsTrue(soil.IsProbabilistic);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(layerData).GetDesignValue(), soil.Cohesion);
                AssertStochasticParameter(layerData.Cohesion, soil.CohesionStochasticParameter);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(layerData).GetDesignValue(), soil.FrictionAngle);
                AssertStochasticParameter(layerData.FrictionAngle, soil.FrictionAngleStochasticParameter);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(layerData).GetDesignValue(), soil.ShearStrengthRatio);
                AssertStochasticParameter(layerData.ShearStrengthRatio, soil.ShearStrengthRatioStochasticParameter);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(layerData).GetDesignValue(), soil.StrengthIncreaseExponent);
                AssertStochasticParameter(layerData.StrengthIncreaseExponent, soil.StrengthIncreaseExponentStochasticParameter);

                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(layerData).GetDesignValue(), soil.VolumetricWeightAbovePhreaticLevel);
                Assert.AreEqual(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(layerData).GetDesignValue(), soil.VolumetricWeightBelowPhreaticLevel);

                Assert.IsFalse(soil.CohesionAndFrictionAngleCorrelated);
                Assert.IsFalse(soil.ShearStrengthRatioAndShearStrengthExponentCorrelated);

                Assert.AreEqual(GetExpectedShearStrengthModelTypeForAbovePhreaticLevel(layerData.ShearStrengthModel), soil.ShearStrengthModelTypeAbovePhreaticLevel);
                Assert.AreEqual(GetExpectedShearStrengthModelTypeForBelowPhreaticLevel(layerData.ShearStrengthModel), soil.ShearStrengthModelTypeBelowPhreaticLevel);

                var dilatancyDistribution = new VariationCoefficientNormalDistribution(2)
                {
                    Mean = (RoundedDouble)1,
                    CoefficientOfVariation = (RoundedDouble)0
                };

                Assert.AreEqual(0, soil.Dilatancy);
                AssertStochasticParameter(dilatancyDistribution, soil.DilatancyStochasticParameter, false);
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="PersistableSoil"/>.
        /// </summary>
        /// <param name="layer">The layer to use.</param>
        /// <param name="idFactory">The factory for creating IDs.</param>
        /// <param name="registry">The persistence registry.</param>
        /// <returns>The created <see cref="PersistableSoil"/>.</returns>
        /// <exception cref="InvalidEnumArgumentException">Thrown when
        /// <see cref="MacroStabilityInwardsShearStrengthModel"/> has an invalid value.</exception>
        /// <exception cref="NotSupportedException">Thrown when <see cref="MacroStabilityInwardsShearStrengthModel"/>
        /// has a valid value but is not supported.</exception>
        private static PersistableSoil Create(MacroStabilityInwardsSoilLayer2D layer, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry)
        {
            MacroStabilityInwardsSoilLayerData layerData = layer.Data;

            var soil = new PersistableSoil
            {
                Id                                                   = idFactory.Create(),
                Name                                                 = layerData.MaterialName,
                IsProbabilistic                                      = true,
                Cohesion                                             = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(layerData).GetDesignValue(),
                CohesionStochasticParameter                          = PersistableStochasticParameterFactory.Create(layerData.Cohesion),
                FrictionAngle                                        = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(layerData).GetDesignValue(),
                FrictionAngleStochasticParameter                     = PersistableStochasticParameterFactory.Create(layerData.FrictionAngle),
                ShearStrengthRatio                                   = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(layerData).GetDesignValue(),
                ShearStrengthRatioStochasticParameter                = PersistableStochasticParameterFactory.Create(layerData.ShearStrengthRatio),
                StrengthIncreaseExponent                             = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(layerData).GetDesignValue(),
                StrengthIncreaseExponentStochasticParameter          = PersistableStochasticParameterFactory.Create(layerData.StrengthIncreaseExponent),
                CohesionAndFrictionAngleCorrelated                   = false,
                ShearStrengthRatioAndShearStrengthExponentCorrelated = false,
                ShearStrengthModelTypeAbovePhreaticLevel             = GetShearStrengthModelTypeForAbovePhreaticLevel(layerData.ShearStrengthModel),
                ShearStrengthModelTypeBelowPhreaticLevel             = GetShearStrengthModelTypeForBelowPhreaticLevel(layerData.ShearStrengthModel),
                VolumetricWeightAbovePhreaticLevel                   = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(layerData).GetDesignValue(),
                VolumetricWeightBelowPhreaticLevel                   = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(layerData).GetDesignValue(),
                Dilatancy                                            = 0,
                DilatancyStochasticParameter                         = PersistableStochasticParameterFactory.Create(new VariationCoefficientNormalDistribution(2)
                {
                    Mean = (RoundedDouble)1,
                    CoefficientOfVariation = (RoundedDouble)0
                }, false)
            };

            soil.Code = $"{soil.Name}-{soil.Id}";

            registry.AddSoil(layer, soil.Id);

            return(soil);
        }
        public void GetAbovePhreaticLevel_ValidSoilLayerData_CreateDesignVariableForAbovePhreaticLevel()
        {
            // Setup
            var data = new MacroStabilityInwardsSoilLayerData
            {
                AbovePhreaticLevel =
                {
                    Mean                   = (RoundedDouble)mean,
                    CoefficientOfVariation = (RoundedDouble)coefficientOfVariation,
                    Shift                  = (RoundedDouble)(mean - 0.1)
                }
            };

            // Call
            VariationCoefficientDeterministicDesignVariable <VariationCoefficientLogNormalDistribution> abovePhreaticLevel = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(data);

            // Assert
            DistributionAssert.AreEqual(data.AbovePhreaticLevel, abovePhreaticLevel.Distribution);
            Assert.AreEqual(data.AbovePhreaticLevel.Mean, abovePhreaticLevel.GetDesignValue());
        }
Exemple #7
0
        /// <summary>
        /// Creates a new instance of <see cref="MacroStabilityInwardsFormattedSoilLayerDataRow"/>.
        /// </summary>
        /// <param name="layerData">The <see cref="MacroStabilityInwardsSoilLayerData"/> to format.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="layerData"/>
        /// is <c>null</c>.</exception>
        public MacroStabilityInwardsFormattedSoilLayerDataRow(MacroStabilityInwardsSoilLayerData layerData)
        {
            if (layerData == null)
            {
                throw new ArgumentNullException(nameof(layerData));
            }

            MaterialName             = SoilLayerDataHelper.GetValidName(layerData.MaterialName);
            Color                    = SoilLayerDataHelper.GetValidColor(layerData.Color);
            IsAquifer                = layerData.IsAquifer;
            AbovePhreaticLevel       = FormatVariationCoefficientDesignVariableWithShift(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(layerData));
            BelowPhreaticLevel       = FormatVariationCoefficientDesignVariableWithShift(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(layerData));
            ShearStrengthModel       = layerData.ShearStrengthModel;
            Cohesion                 = FormatVariationCoefficientDesignVariable(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(layerData));
            FrictionAngle            = FormatVariationCoefficientDesignVariable(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(layerData));
            ShearStrengthRatio       = FormatVariationCoefficientDesignVariable(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(layerData));
            StrengthIncreaseExponent = FormatVariationCoefficientDesignVariable(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(layerData));
            UsePop                   = layerData.UsePop;
            Pop = FormatVariationCoefficientDesignVariable(MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPop(layerData));
        }