/// <summary> /// Transforms the generic <paramref name="soilLayer"/> into one or more <see cref="PipingSoilLayer"/>. /// </summary> /// <param name="soilLayer">The soil layer to use in the transformation.</param> /// <param name="atX">The 1D intersection of the profile.</param> /// <param name="bottom">The bottom of the soil layer.</param> /// <returns>A collection of <see cref="PipingSoilLayer"/> based on the given data.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilLayer"/> is <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> public static IEnumerable <PipingSoilLayer> Transform(SoilLayer2D soilLayer, double atX, out double bottom) { bottom = double.MaxValue; var soilLayers = new Collection <PipingSoilLayer>(); Transform(soilLayer, atX, soilLayers, ref bottom); return(soilLayers); }
/// <summary> /// Transforms the generic <paramref name="soilLayer"/> into one or more <see cref="PipingSoilLayer"/>. /// </summary> /// <param name="soilLayer">The soil layer to use in the transformation.</param> /// <param name="atX">The 1D intersection of the profile.</param> /// <param name="soilLayers">The collection of transformed piping soil layers to add the /// transformation to.</param> /// <param name="bottom">The bottom of the soil layer.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilLayer"/> is <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> private static void Transform(SoilLayer2D soilLayer, double atX, ICollection <PipingSoilLayer> soilLayers, ref double bottom) { if (soilLayer == null) { throw new ArgumentNullException(nameof(soilLayer)); } ValidateStochasticParameters(soilLayer); if (soilLayer.OuterLoop == null) { return; } string soilLayerName = soilLayer.MaterialName; double[] outerLoopIntersectionHeights = GetLoopIntersectionHeights(soilLayer.OuterLoop.Segments, atX, soilLayerName).ToArray(); if (!outerLoopIntersectionHeights.Any()) { return; } IEnumerable <IEnumerable <double> > innerLoopsIntersectionHeights = soilLayer.NestedLayers.Select(l => GetLoopIntersectionHeights(l.OuterLoop.Segments, atX, soilLayerName)); IEnumerable <Tuple <double, double> > innerLoopIntersectionHeightPairs = GetOrderedStartAndEndPairsIn1D(innerLoopsIntersectionHeights).ToList(); IEnumerable <Tuple <double, double> > outerLoopIntersectionHeightPairs = GetOrderedStartAndEndPairsIn1D(outerLoopIntersectionHeights).ToList(); double currentBottom = outerLoopIntersectionHeightPairs.First().Item1; var heights = new List <double>(); heights.AddRange(innerLoopIntersectionHeightPairs.Where(p => p.Item1 >= currentBottom).Select(p => p.Item1)); heights.AddRange(outerLoopIntersectionHeightPairs.Select(p => p.Item2)); foreach (double height in heights.Where(height => !innerLoopIntersectionHeightPairs.Any(tuple => HeightInInnerLoop(tuple, height)))) { var pipingSoilLayer = new PipingSoilLayer(height) { IsAquifer = TransformIsAquifer(soilLayer.IsAquifer, soilLayerName), MaterialName = soilLayer.MaterialName, Color = SoilLayerColorConverter.Convert(soilLayer.Color) }; SetStochasticParameters(pipingSoilLayer, soilLayer); soilLayers.Add(pipingSoilLayer); } bottom = currentBottom < bottom ? currentBottom : bottom; foreach (SoilLayer2D nestedLayer in soilLayer.NestedLayers) { Transform(nestedLayer, atX, soilLayers, ref bottom); } }
public void Transform_SoilProfile2DWithLayerFilledWithOtherLayer_ReturnsProfileWithBottomAndLayers() { // Setup const string profileName = "SomeProfile"; const long pipingSoilProfileId = 1234L; List <Segment2D> loopHole = Segment2DLoopCollectionHelper.CreateFromString( string.Join(Environment.NewLine, "5", ".....", ".4.1.", ".3.2.", ".....", ".....")); SoilLayer2D soilLayer2D = SoilLayer2DTestFactory.CreateSoilLayer2D( new[] { loopHole }, Segment2DLoopCollectionHelper.CreateFromString( string.Join(Environment.NewLine, "5", "2...3", ".....", ".....", ".....", "1...4"))); var profile = new SoilProfile2D(pipingSoilProfileId, profileName, new List <SoilLayer2D> { soilLayer2D, SoilLayer2DTestFactory.CreateSoilLayer2D( new List <Segment2D[]>(), loopHole) }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = 2.0 }; // Call PipingSoilProfile transformed = PipingSoilProfileTransformer.Transform(profile); // Assert Assert.AreEqual(profileName, transformed.Name); Assert.AreEqual(SoilProfileType.SoilProfile2D, transformed.SoilProfileSourceType); Assert.AreEqual(4, transformed.Layers.Count()); CollectionAssert.AreEquivalent(new[] { 4.0, 3.0, 3.0, 2.0 }, transformed.Layers.Select(rl => rl.Top)); Assert.AreEqual(0, transformed.Bottom); }
/// <summary> /// Transforms the generic <paramref name="soilLayer"/> into a /// <see cref="MacroStabilityInwardsSoilLayer2D"/>. /// </summary> /// <param name="soilLayer">The soil layer to use in the transformation.</param> /// <returns>A <see cref="MacroStabilityInwardsSoilLayer1D"/> based on the given data.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilLayer"/> is /// <c>null</c>.</exception> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> public static MacroStabilityInwardsSoilLayer2D Transform(SoilLayer2D soilLayer) { if (soilLayer == null) { throw new ArgumentNullException(nameof(soilLayer)); } ValidateStochasticParameters(soilLayer); return(ConvertLayerRecursively(soilLayer)); }
public void SoilLayer2DTransform_IncorrectShiftedLogNormalDistribution_ThrowsImportedDataTransformException( SoilLayer2D layer, string parameterName) { // Call TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert Exception exception = Assert.Throws <ImportedDataTransformException>(test); string expectedMessage = CreateExpectedErrorMessageForParameterVariable(layer.MaterialName, parameterName, "Parameter moet verschoven lognormaal verdeeld zijn."); Assert.AreEqual(expectedMessage, exception.Message); }
public void SoilLayer2DTransform_ValidIsAquifer_ReturnsMacroStabilityInwardsSoilLayer2D(double isAquifer, bool transformedIsAquifer) { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.IsAquifer = isAquifer; // Call MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert Assert.AreEqual(transformedIsAquifer, soilLayer2D.Data.IsAquifer); }
public void SoilLayer2DTransform_ValidUsePopValue_ReturnMacroStabilityInwardSoilLayer2D(double?usePop, bool transformedUsePopValue) { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.UsePop = usePop; // Call MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert Assert.AreEqual(transformedUsePopValue, soilLayer2D.Data.UsePop); }
public void SoilLayer2DTransform_ValidColors_ReturnsMacroStabilityInwardsSoilLayer2D(double?color, Color transformedColor) { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.Color = color; // Call MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert Assert.AreEqual(transformedColor, soilLayer2D.Data.Color); }
public void Constructor_ExpectedPropertiesSet() { // Setup var outerLoop = new SoilLayer2DLoop(new Segment2D[0]); IEnumerable <SoilLayer2D> nestedLayers = Enumerable.Empty <SoilLayer2D>(); // Call var layer = new SoilLayer2D(outerLoop, nestedLayers); // Assert Assert.IsInstanceOf <SoilLayerBase>(layer); Assert.AreSame(outerLoop, layer.OuterLoop); Assert.AreSame(nestedLayers, layer.NestedLayers); }
public void SoilLayer2DTransform_ValidShearStrengthModelValue_ReturnMacroStabilityInwardSoilLayer2D(double?shearStrengthModel, MacroStabilityInwardsShearStrengthModel transformedShearStrengthModel) { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.ShearStrengthModel = shearStrengthModel; // Call MacroStabilityInwardsSoilLayer2D soilLayer2D = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert Assert.AreEqual(transformedShearStrengthModel, soilLayer2D.Data.ShearStrengthModel); }
private static void AssertSoilData(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual) { Assert.AreEqual(original.MaterialName, actual.Data.MaterialName); Assert.AreEqual(original.IsAquifer.Equals(1.0), actual.Data.IsAquifer); Assert.AreEqual(Color.FromArgb(Convert.ToInt32(original.Color)), actual.Data.Color); MacroStabilityInwardsSoilLayerData soilLayerData = actual.Data; Assert.AreEqual(original.AbovePhreaticLevelMean, soilLayerData.AbovePhreaticLevel.Mean, soilLayerData.AbovePhreaticLevel.GetAccuracy()); Assert.AreEqual(original.AbovePhreaticLevelCoefficientOfVariation, soilLayerData.AbovePhreaticLevel.CoefficientOfVariation, soilLayerData.AbovePhreaticLevel.GetAccuracy()); Assert.AreEqual(original.AbovePhreaticLevelShift, soilLayerData.AbovePhreaticLevel.Shift, soilLayerData.AbovePhreaticLevel.GetAccuracy()); Assert.AreEqual(original.BelowPhreaticLevelMean, soilLayerData.BelowPhreaticLevel.Mean, soilLayerData.BelowPhreaticLevel.GetAccuracy()); Assert.AreEqual(original.BelowPhreaticLevelCoefficientOfVariation, soilLayerData.BelowPhreaticLevel.CoefficientOfVariation, soilLayerData.BelowPhreaticLevel.GetAccuracy()); Assert.AreEqual(original.BelowPhreaticLevelShift, soilLayerData.BelowPhreaticLevel.Shift, soilLayerData.BelowPhreaticLevel.GetAccuracy()); Assert.AreEqual(original.CohesionMean, soilLayerData.Cohesion.Mean, soilLayerData.Cohesion.GetAccuracy()); Assert.AreEqual(original.CohesionCoefficientOfVariation, soilLayerData.Cohesion.CoefficientOfVariation, soilLayerData.Cohesion.GetAccuracy()); Assert.AreEqual(original.FrictionAngleMean, soilLayerData.FrictionAngle.Mean, soilLayerData.FrictionAngle.GetAccuracy()); Assert.AreEqual(original.FrictionAngleCoefficientOfVariation, soilLayerData.FrictionAngle.CoefficientOfVariation, soilLayerData.FrictionAngle.GetAccuracy()); Assert.AreEqual(original.ShearStrengthRatioMean, soilLayerData.ShearStrengthRatio.Mean, soilLayerData.ShearStrengthRatio.GetAccuracy()); Assert.AreEqual(original.ShearStrengthRatioCoefficientOfVariation, soilLayerData.ShearStrengthRatio.CoefficientOfVariation, soilLayerData.ShearStrengthRatio.GetAccuracy()); Assert.AreEqual(original.StrengthIncreaseExponentMean, soilLayerData.StrengthIncreaseExponent.Mean, soilLayerData.StrengthIncreaseExponent.GetAccuracy()); Assert.AreEqual(original.StrengthIncreaseExponentCoefficientOfVariation, soilLayerData.StrengthIncreaseExponent.CoefficientOfVariation, soilLayerData.StrengthIncreaseExponent.GetAccuracy()); Assert.AreEqual(original.PopMean, soilLayerData.Pop.Mean, soilLayerData.Pop.GetAccuracy()); Assert.AreEqual(original.PopCoefficientOfVariation, soilLayerData.Pop.CoefficientOfVariation, soilLayerData.Pop.GetAccuracy()); }
public void Transform_ValidStochasticSoilModelWithSoilProfile2D_ReturnsExpectedPipingStochasticSoilModel() { // Setup var random = new Random(21); const string name = "name"; const double intersectionX = 1.0; SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); var profile = new SoilProfile2D(0, "SoilProfile2D", new[] { layer }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = intersectionX }; var transformer = new PipingStochasticSoilModelTransformer(); double probability = random.NextDouble(); var soilModel = new StochasticSoilModel(name, FailureMechanismType.Piping) { StochasticSoilProfiles = { new StochasticSoilProfile(probability, profile) }, Geometry = { new Point2D(1.0, 0.0), new Point2D(0.0, 0.0) } }; // Call PipingStochasticSoilModel transformed = transformer.Transform(soilModel); // Assert Assert.AreEqual(name, transformed.Name); Assert.AreEqual(1, transformed.StochasticSoilProfiles.Count()); CollectionAssert.AreEqual(soilModel.Geometry, transformed.Geometry); var expectedPipingSoilProfile = new[] { new PipingStochasticSoilProfile(probability, PipingSoilProfileTransformer.Transform(profile)) }; AssertPipingStochasticSoilProfiles(expectedPipingSoilProfile, transformed.StochasticSoilProfiles.ToArray()); }
public void SoilLayer2DTransform_InvalidShearStrengthModelValue_ThrowsImportedDataTransformException() { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.ShearStrengthModel = 2; // Call TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, "Ongeldige waarde voor parameter 'Schuifsterkte model'."); Assert.AreEqual(expectedMessage, exception.Message); }
public void SoilLayer2DTransform_ShearStrengthModelValueNone_ThrowsImportedDataTransformException() { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.ShearStrengthModel = 1; // Call TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert var exception = Assert.Throws <ImportedDataTransformException>(call); string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, "Er is geen schuifsterkte model opgegeven."); Assert.AreEqual(expectedMessage, exception.Message); }
public void SoilLayer2DTransform_InvalidUsePopValue_ReturnMacroStabilityInwardSoilLayer2D() { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.UsePop = 1; // Call TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, "Ongeldige waarde voor parameter 'Gebruik POP'."); Assert.AreEqual(expectedMessage, exception.Message); }
public void SoilLayer2DTransform_InvalidIsAquifer_ThrowsImportedDataException(double?isAquifer) { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); layer.IsAquifer = isAquifer; // Call TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert var exception = Assert.Throws <ImportedDataTransformException>(call); string expectedMessage = CreateExpectedErrorMessage(layer.MaterialName, "Ongeldige waarde voor parameter 'Is aquifer'."); Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf <NotSupportedException>(exception.InnerException); }
public void SoilLayer2DTransform_PropertiesSetAndValid_ReturnMacroStabilityInwardSoilLayer2D() { // Setup var nestedLayer1 = new SoilLayer2D(CreateRandomLoop(21), Enumerable.Empty <SoilLayer2D>()); var nestedLayer2 = new SoilLayer2D(CreateRandomLoop(22), Enumerable.Empty <SoilLayer2D>()); var nestedLayer3 = new SoilLayer2D(CreateRandomLoop(22), new[] { nestedLayer2 }); var layer = new SoilLayer2D(CreateRandomLoop(23), new[] { nestedLayer1, nestedLayer3 }); SetRandomSoilData(nestedLayer1, 21, "Nested sand"); SetRandomSoilData(nestedLayer2, 22, "Nested gold"); SetRandomSoilData(nestedLayer3, 23, "Nested clay"); SetRandomSoilData(layer, 24, "Sand"); // Call MacroStabilityInwardsSoilLayer2D transformedLayer = MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert AssertSoilLayer(layer, transformedLayer); Assert.AreEqual(2, transformedLayer.NestedLayers.Count()); MacroStabilityInwardsSoilLayer2D transformedNestedLayer1 = transformedLayer.NestedLayers.ElementAt(0); AssertSoilLayer(nestedLayer1, transformedNestedLayer1); CollectionAssert.IsEmpty(transformedNestedLayer1.NestedLayers); MacroStabilityInwardsSoilLayer2D transformedNestedLayer3 = transformedLayer.NestedLayers.ElementAt(1); AssertSoilLayer(nestedLayer3, transformedNestedLayer3); Assert.AreEqual(1, transformedNestedLayer3.NestedLayers.Count()); MacroStabilityInwardsSoilLayer2D transformedNestedLayer2 = transformedNestedLayer3.NestedLayers.ElementAt(0); AssertSoilLayer(nestedLayer2, transformedNestedLayer2); CollectionAssert.IsEmpty(transformedNestedLayer2.NestedLayers); }
public void Transform_ValidStochasticSoilModelWithSameProfileInTwoStochasticSoilProfiles_ReturnsExpectedPipingStochasticSoilModel() { // Setup const string soilModelName = "name"; const string soilProfileName = "SoilProfile"; const double intersectionX = 1.0; SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); var profile = new SoilProfile2D(0, soilProfileName, new[] { layer }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = intersectionX }; const double originalProfileOneProbability = 0.2; const double originalProfileTwoProbability = 0.7; StochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(soilModelName, new[] { new StochasticSoilProfile(originalProfileOneProbability, profile), new StochasticSoilProfile(originalProfileTwoProbability, profile) }); var transformer = new PipingStochasticSoilModelTransformer(); PipingStochasticSoilModel transformed = null; // Call Action call = () => transformed = transformer.Transform(soilModel); // Assert string expectedMessage = $"Ondergrondschematisatie '{soilProfileName}' is meerdere keren gevonden in ondergrondmodel '{soilModelName}'. " + "Kansen van voorkomen worden opgeteld."; TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Warn)); PipingStochasticSoilProfile[] transformedStochasticSoilProfiles = transformed.StochasticSoilProfiles.ToArray(); Assert.AreEqual(1, transformedStochasticSoilProfiles.Length); const double expectedProbability = originalProfileOneProbability + originalProfileTwoProbability; Assert.AreEqual(expectedProbability, transformedStochasticSoilProfiles[0].Probability, 1e-6); }
public void Transform_ValidTwoStochasticSoilModelWithSameProfile_ReturnsExpectedPipingStochasticSoilModel() { // Setup const double intersectionX = 1.0; SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); var profile = new SoilProfile2D(0, "SoilProfile2D", new[] { layer }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = intersectionX }; var transformer = new PipingStochasticSoilModelTransformer(); StochasticSoilModel soilModel1 = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(new[] { StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile) }); StochasticSoilModel soilModel2 = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(new[] { StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile) }); // Call PipingStochasticSoilModel transformed1 = transformer.Transform(soilModel1); PipingStochasticSoilModel transformed2 = transformer.Transform(soilModel2); // Assert PipingStochasticSoilProfile[] transformedStochasticSoilProfiles1 = transformed1.StochasticSoilProfiles.ToArray(); PipingStochasticSoilProfile[] transformedStochasticSoilProfiles2 = transformed2.StochasticSoilProfiles.ToArray(); Assert.AreEqual(1, transformedStochasticSoilProfiles1.Length); Assert.AreEqual(1, transformedStochasticSoilProfiles2.Length); PipingStochasticSoilProfile pipingStochasticSoilProfile1 = transformedStochasticSoilProfiles1[0]; PipingStochasticSoilProfile pipingStochasticSoilProfile2 = transformedStochasticSoilProfiles2[0]; Assert.AreSame(pipingStochasticSoilProfile1.SoilProfile, pipingStochasticSoilProfile2.SoilProfile); }
public void Transform_SoilProfile2DLayerWithVerticalLineOnXInXml_ThrowsImportedDataTransformException() { // Setup const string profileName = "SomeProfile"; const double atX = 0.0; SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D( new List <Segment2D[]>(), new List <Segment2D> { new Segment2D(new Point2D(atX, 0.0), new Point2D(atX, 1.0)), new Segment2D(new Point2D(atX, 1.0), new Point2D(0.5, 0.5)), new Segment2D(new Point2D(0.5, 0.5), new Point2D(atX, 0.0)) }); var profile = new SoilProfile2D(0, profileName, new[] { layer }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = atX }; // Call TestDelegate test = () => PipingSoilProfileTransformer.Transform(profile); // Assert var exception = Assert.Throws <ImportedDataTransformException>(test); string message = $"Er is een fout opgetreden bij het inlezen van grondlaag '{layer.MaterialName}': " + "Er kan geen 1D-profiel bepaald worden wanneer segmenten in een 2D " + $"laag verticaal lopen op de gekozen positie: x = {atX}."; Assert.AreEqual(message, exception.Message); }
public void Transform_SoilProfile2DWithSingleLayerOnlyOuterLoop_ReturnsProfileWithBottomAndALayer() { // Setup const string profileName = "SomeProfile"; var firstPoint = new Point2D(-0.5, 1.0); var secondPoint = new Point2D(0.5, 1.0); var thirdPoint = new Point2D(0.5, -1.0); var fourthPoint = new Point2D(-0.5, -1.0); SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D( new List <Segment2D[]>(), new List <Segment2D> { new Segment2D(firstPoint, secondPoint), new Segment2D(secondPoint, thirdPoint), new Segment2D(thirdPoint, fourthPoint), new Segment2D(fourthPoint, firstPoint) }); var profile = new SoilProfile2D(0, profileName, new[] { layer }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = 0.0 }; // Call PipingSoilProfile transformed = PipingSoilProfileTransformer.Transform(profile); // Assert Assert.AreEqual(profileName, transformed.Name); Assert.AreEqual(1, transformed.Layers.Count()); Assert.AreEqual(1.0, transformed.Layers.ToArray()[0].Top); Assert.AreEqual(-1.0, transformed.Bottom); Assert.AreEqual(SoilProfileType.SoilProfile2D, transformed.SoilProfileSourceType); }
public void Transform_ValidSoilProfile2D_ReturnsExpectedPipingSoilProfile() { // Setup const string name = "name"; const double bottom = 0.5; const double intersectionX = 1.0; SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(new List <Segment2D[]>(), new List <Segment2D> { new Segment2D(new Point2D(1.0, bottom), new Point2D(1.2, 1)), new Segment2D(new Point2D(1.2, 1), new Point2D(1.0, bottom)) }); var profile = new SoilProfile2D(0, name, new[] { layer }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = intersectionX }; // Call PipingSoilProfile transformed = PipingSoilProfileTransformer.Transform(profile); // Assert Assert.AreEqual(name, transformed.Name); Assert.AreEqual(SoilProfileType.SoilProfile2D, transformed.SoilProfileSourceType); Assert.AreEqual(bottom, transformed.Bottom); double bottomOut; IEnumerable <PipingSoilLayer> actualPipingSoilLayers = PipingSoilLayerTransformer.Transform( layer, intersectionX, out bottomOut); AssertPipingSoilLayers(actualPipingSoilLayers, transformed.Layers); }
public void Transform_TwoStochasticSoilModelsWithSameProfile_ReturnExpectedMacroStabilityInwardsStochasticSoilModel() { // Setup SoilLayer2D layer = SoilLayer2DTestFactory.CreateSoilLayer2D(); var profile = new SoilProfile2D(2, "test", new[] { layer }, Enumerable.Empty <PreconsolidationStress>()); StochasticSoilModel soilModel1 = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateMacroStabilityInwardsStochasticSoilModelWithGeometry(new[] { StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile) }); StochasticSoilModel soilModel2 = MacroStabilityInwardsStochasticSoilModelTestFactory.CreateMacroStabilityInwardsStochasticSoilModelWithGeometry(new[] { StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(profile) }); var transformer = new MacroStabilityInwardsStochasticSoilModelTransformer(); // Call MacroStabilityInwardsStochasticSoilModel transformedModel1 = transformer.Transform(soilModel1); MacroStabilityInwardsStochasticSoilModel transformedModel2 = transformer.Transform(soilModel2); // Assert MacroStabilityInwardsStochasticSoilProfile[] transformedStochasticSoilProfiles1 = transformedModel1.StochasticSoilProfiles.ToArray(); MacroStabilityInwardsStochasticSoilProfile[] transformedStochasticSoilProfiles2 = transformedModel2.StochasticSoilProfiles.ToArray(); Assert.AreEqual(1, transformedStochasticSoilProfiles1.Length); Assert.AreEqual(1, transformedStochasticSoilProfiles2.Length); MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile1 = transformedStochasticSoilProfiles1[0]; MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile2 = transformedStochasticSoilProfiles2[0]; Assert.AreSame(stochasticSoilProfile1.SoilProfile, stochasticSoilProfile2.SoilProfile); }
public void ReadSoilProfile_DatabaseWith2DSoilProfileContainingNestedLayers_ReturnOneProfile() { // Setup string dbFile = Path.Combine(testDataPath, "2dprofileNestedLayers.soil"); using (var reader = new SoilProfile2DReader(dbFile)) { reader.Initialize(); // Call SoilProfile2D soilProfile2D = reader.ReadSoilProfile(); // Assert Assert.AreEqual(1, soilProfile2D.Id); Assert.AreEqual("Profile", soilProfile2D.Name); CollectionAssert.IsEmpty(soilProfile2D.PreconsolidationStresses); Assert.AreEqual(90.0, soilProfile2D.IntersectionX, 1e-3); Assert.AreEqual(1, soilProfile2D.Layers.Count()); SoilLayer2D layer = soilProfile2D.Layers.First(); Assert.AreEqual("Material1", layer.MaterialName); Assert.AreEqual(2, layer.NestedLayers.Count()); SoilLayer2D firstNestedLayer = layer.NestedLayers.First(); Assert.AreEqual("Material4", firstNestedLayer.MaterialName); Assert.AreEqual(1, firstNestedLayer.NestedLayers.Count()); Assert.AreEqual("Material3", firstNestedLayer.NestedLayers.First().MaterialName); Assert.AreEqual(0, firstNestedLayer.NestedLayers.First().NestedLayers.Count()); SoilLayer2D secondNestedLayer = layer.NestedLayers.ElementAt(1); Assert.AreEqual("Material2", secondNestedLayer.MaterialName); Assert.AreEqual(0, secondNestedLayer.NestedLayers.Count()); } Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); }
private static void SetRandomSoilData(SoilLayer2D layer, int seed, string materialName) { var random = new Random(seed); layer.MaterialName = materialName; layer.IsAquifer = random.Next(0, 2); layer.Color = random.NextDouble(); layer.AbovePhreaticLevelMean = random.NextDouble() + 1; layer.AbovePhreaticLevelCoefficientOfVariation = random.NextDouble(); layer.AbovePhreaticLevelShift = random.NextDouble(); layer.BelowPhreaticLevelMean = random.NextDouble() + 1; layer.BelowPhreaticLevelCoefficientOfVariation = random.NextDouble(); layer.BelowPhreaticLevelShift = random.NextDouble(); layer.CohesionMean = random.NextDouble(); layer.CohesionCoefficientOfVariation = random.NextDouble(); layer.FrictionAngleMean = random.NextDouble(); layer.FrictionAngleCoefficientOfVariation = random.NextDouble(); layer.ShearStrengthRatioMean = random.NextDouble(); layer.ShearStrengthRatioCoefficientOfVariation = random.NextDouble(); layer.StrengthIncreaseExponentMean = random.NextDouble(); layer.StrengthIncreaseExponentCoefficientOfVariation = random.NextDouble(); layer.PopMean = random.NextDouble(); layer.PopCoefficientOfVariation = random.NextDouble(); }
public void SoilLayer2DTransform_SoilLayer2DWithInvalidLoops_ThrowsImportedDataException(SoilLayer2D soilLayer) { // Call TestDelegate call = () => MacroStabilityInwardsSoilLayerTransformer.Transform(soilLayer); // Assert var exception = Assert.Throws <ImportedDataTransformException>(call); string expectedMessage = CreateExpectedErrorMessage(soilLayer.MaterialName, "De laag bevat een ongeldige geometrie."); Assert.AreEqual(expectedMessage, exception.Message); Assert.IsInstanceOf <ArgumentException>(exception.InnerException); }
/// <summary> /// Converts <see cref="SoilLayer2D"/> into <see cref="MacroStabilityInwardsSoilLayer2D"/>. /// </summary> /// <param name="soilLayer">The soil layer to convert.</param> /// <returns>The converted <see cref="MacroStabilityInwardsSoilLayer2D"/>.</returns> /// <exception cref="ImportedDataTransformException">Thrown when transformation would not result /// in a valid transformed instance.</exception> private static MacroStabilityInwardsSoilLayer2D ConvertLayerRecursively(SoilLayer2D soilLayer) { return(new MacroStabilityInwardsSoilLayer2D(TransformSegmentsToRing(soilLayer.OuterLoop.Segments, soilLayer.MaterialName), ConvertSoilLayerData(soilLayer), soilLayer.NestedLayers.Select(ConvertLayerRecursively).ToArray())); }
public void SoilLayer2DTransform_InvalidStochasticDistributionValues_ThrowImportedDataTransformException(SoilLayer2D layer, string parameterName) { // Call TestDelegate test = () => MacroStabilityInwardsSoilLayerTransformer.Transform(layer); // Assert Exception exception = Assert.Throws <ImportedDataTransformException>(test); Exception innerException = exception.InnerException; Assert.IsInstanceOf <ArgumentOutOfRangeException>(innerException); string expectedMessage = CreateExpectedErrorMessageForParameterVariable(layer.MaterialName, parameterName, innerException.Message); Assert.AreEqual(expectedMessage, exception.Message); }
private static void AssertSoilLayer(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual) { AssertOuterRing(original, actual); AssertSoilData(original, actual); }
private static void AssertOuterRing(SoilLayer2D original, MacroStabilityInwardsSoilLayer2D actual) { Assert.AreEqual(GetRingFromSegments(original.OuterLoop.Segments), actual.OuterRing); }