public void Create_WithValidData_ReturnsPersistableStates() { // Setup MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] { MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)) }); IMacroStabilityInwardsSoilLayer lastLayer = stochasticSoilProfile.SoilProfile.Layers.Last(); lastLayer.Data.UsePop = true; lastLayer.Data.Pop = new VariationCoefficientLogNormalDistribution { Mean = (RoundedDouble)1, CoefficientOfVariation = (RoundedDouble)2 }; calculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile; IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine; var idFactory = new IdFactory(); var registry = new MacroStabilityInwardsExportRegistry(); PersistableGeometryFactory.Create(soilProfile, idFactory, registry); // Call IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry); // Assert PersistableDataModelTestHelper.AssertStates(soilProfile, states); PersistableState state = states.First(); Assert.AreEqual(registry.States[MacroStabilityInwardsExportStageType.Daily], state.Id); }
public void Create_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_ReturnsPersistableStates() { // Setup MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput( new TestHydraulicBoundaryLocation()); calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] { MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)), MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2)) }); IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine; var idFactory = new IdFactory(); var registry = new MacroStabilityInwardsExportRegistry(); PersistableGeometryFactory.Create(soilProfile, idFactory, registry); // Call IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry); // Assert Assert.AreEqual(1, states.Count()); PersistableState state = states.First(); Assert.IsNotNull(state.Id); CollectionAssert.IsEmpty(state.StateLines); CollectionAssert.IsEmpty(state.StatePoints); }
/// <summary> /// Creates a new instance of <see cref="PersistableSoilCollection"/>. /// </summary> /// <param name="soilProfile">The soil profile to use.</param> /// <param name="idFactory">The factory for creating IDs.</param> /// <param name="registry">The persistence registry.</param> /// <returns>The created <see cref="PersistableSoilCollection"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <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> public static PersistableSoilCollection Create(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } if (idFactory == null) { throw new ArgumentNullException(nameof(idFactory)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } return(new PersistableSoilCollection { Soils = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers) .Select(l => Create(l, idFactory, registry)) .ToArray() }); }
/// <summary> /// Asserts whether <paramref name="actual"/> corresponds to <paramref name="original"/>. /// </summary> /// <param name="original">The original <see cref="IMacroStabilityInwardsSoilProfileUnderSurfaceLine"/>.</param> /// <param name="actual">The actual <see cref="SoilProfile"/>.</param> /// <exception cref="AssertionException">Thrown when <paramref name="actual"/> /// does not correspond to <paramref name="original"/>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="original"/> /// contains an invalid value of the enum <see cref="MacroStabilityInwardsShearStrengthModel"/>.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="original"/> /// contains an unsupported value of <see cref="MacroStabilityInwardsShearStrengthModel"/>.</exception> public static void AssertSoilProfile(IMacroStabilityInwardsSoilProfileUnderSurfaceLine original, SoilProfile actual) { MacroStabilityInwardsSoilLayer2D[] expectedLayers = original.Layers.ToArray(); SoilLayer[] actualLayers = actual.Layers.ToArray(); IMacroStabilityInwardsPreconsolidationStress[] expectedPreconsolidationStresses = original.PreconsolidationStresses.ToArray(); PreconsolidationStress[] actualPreconsolidationStresses = actual.PreconsolidationStresses.ToArray(); AssertLayers(expectedLayers, actualLayers); AssertPreconsolidationStresses(expectedPreconsolidationStresses, actualPreconsolidationStresses); }
/// <summary> /// Converts <see cref="IMacroStabilityInwardsSoilProfileUnderSurfaceLine"/> /// into <see cref="SoilProfile"/>. /// </summary> /// <param name="soilProfile">The soil profile to convert.</param> /// <returns>The converted <see cref="SoilProfile"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/> /// is <c>null</c>.</exception> /// <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> public static SoilProfile Convert(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } IEnumerable <SoilLayer> layers = ConvertLayers(soilProfile.Layers); IEnumerable <PreconsolidationStress> preconsolidationStresses = ConvertPreconsolidationStresses(soilProfile.PreconsolidationStresses); return(new SoilProfile(layers, preconsolidationStresses)); }
private static PersistableGeometry CreateGeometry(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, MacroStabilityInwardsExportStageType stageType, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { var geometry = new PersistableGeometry { Id = idFactory.Create(), Layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers) .Select(l => CreateLayer(l, stageType, idFactory, registry)) .ToArray() }; registry.AddGeometry(stageType, geometry.Id); return(geometry); }
/// <summary> /// Creates a new <see cref="PersistableDataModel"/>. /// </summary> /// <param name="calculation">The calculation to get the data from.</param> /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param> /// <param name="getNormativeAssessmentLevelFunc"><see cref="Func{TResult}"/> /// for obtaining the normative assessment level.</param> /// <param name="filePath">The filePath that is used.</param> /// <returns>A created <see cref="PersistableDataModel"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, /// <paramref name="generalInput"/> or <paramref name="getNormativeAssessmentLevelFunc"/> is <c>null</c>.</exception> /// <exception cref="InvalidOperationException">Thrown when <paramref name="calculation"/> /// has no output.</exception> public static PersistableDataModel Create(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, Func <RoundedDouble> getNormativeAssessmentLevelFunc, string filePath) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } if (getNormativeAssessmentLevelFunc == null) { throw new ArgumentNullException(nameof(getNormativeAssessmentLevelFunc)); } if (!calculation.HasOutput) { throw new InvalidOperationException("Calculation must have output."); } var idFactory = new IdFactory(); var registry = new MacroStabilityInwardsExportRegistry(); MacroStabilityInwardsInput input = calculation.InputParameters; IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = input.SoilProfileUnderSurfaceLine; return(new PersistableDataModel { Info = PersistableProjectInfoFactory.Create(calculation, filePath), CalculationSettings = PersistableCalculationSettingsFactory.Create(calculation.Output.SlidingCurve, idFactory, registry), Soils = PersistableSoilCollectionFactory.Create(soilProfile, idFactory, registry), Geometry = PersistableGeometryFactory.Create(soilProfile, idFactory, registry), SoilLayers = PersistableSoilLayerCollectionFactory.Create(soilProfile, idFactory, registry), Waternets = PersistableWaternetFactory.Create( DerivedMacroStabilityInwardsInput.GetWaternetDaily(input, generalInput), DerivedMacroStabilityInwardsInput.GetWaternetExtreme(input, generalInput, GetEffectiveAssessmentLevel(input, getNormativeAssessmentLevelFunc)), generalInput, idFactory, registry), WaternetCreatorSettings = PersistableWaternetCreatorSettingsFactory.Create(input, GetEffectiveAssessmentLevel(input, getNormativeAssessmentLevelFunc), idFactory, registry), States = PersistableStateFactory.Create(soilProfile, idFactory, registry), Stages = PersistableStageFactory.Create(idFactory, registry) }); }
private static PersistableSoilLayerCollection CreateSoilLayerCollection(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, MacroStabilityInwardsExportStageType stageType, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { var soilLayerCollection = new PersistableSoilLayerCollection { Id = idFactory.Create(), SoilLayers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers) .Select(l => Create(l, stageType, registry)) .ToArray() }; registry.AddSoilLayer(stageType, soilLayerCollection.Id); return(soilLayerCollection); }
/// <summary> /// Asserts whether the <see cref="PersistableState"/> contains the data /// that is representative for the <paramref name="soilProfile"/>. /// </summary> /// <param name="soilProfile">The input that contains the original data.</param> /// <param name="states">The <see cref="PersistableState"/> /// that needs to be asserted.</param> /// <exception cref="AssertionException">Thrown when the data in <paramref name="states"/> /// is not correct.</exception> public static void AssertStates(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, IEnumerable <PersistableState> states) { Assert.AreEqual(1, states.Count()); IEnumerable <MacroStabilityInwardsSoilLayer2D> layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers); for (var i = 0; i < states.Count(); i++) { PersistableState state = states.ElementAt(i); Assert.IsNotNull(state.Id); CollectionAssert.IsEmpty(state.StateLines); AssertPopStatePoints(layers, state.StatePoints.Where(sp => sp.Stress.StateType == PersistableStateType.Pop)); AssertYieldStressStatePoints(layers, soilProfile.PreconsolidationStresses, state.StatePoints.Where(sp => sp.Stress.StateType == PersistableStateType.YieldStress)); } }
/// <summary> /// Indicator whether a <paramref name="soilProfile"/> has valid state points. /// </summary> /// <param name="soilProfile">The <see cref="IMacroStabilityInwardsSoilProfileUnderSurfaceLine"/> to get the state points from.</param> /// <returns><c>true</c> when every layer in <paramref name="soilProfile"/> has max. 1 state point; <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/> is <c>null</c>.</exception> public static bool HasValidStatePoints(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } MacroStabilityInwardsSoilLayer2D[] layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers).ToArray(); Dictionary <IMacroStabilityInwardsPreconsolidationStress, MacroStabilityInwardsSoilLayer2D> stressesWithLayers = soilProfile.PreconsolidationStresses.ToDictionary(pcs => pcs, pcs => GetLayerForPreconsolidationStress(layers, pcs)); IEnumerable <IGrouping <MacroStabilityInwardsSoilLayer2D, IMacroStabilityInwardsPreconsolidationStress> > duplicateLayers = stressesWithLayers.ToLookup(pair => pair.Value, pair => pair.Key).Where(x => x.Count() > 1); return(!duplicateLayers.Any() && stressesWithLayers.All(pair => pair.Value != null) && !stressesWithLayers.Any(stressWithLayer => stressWithLayer.Value.Data.UsePop && HasValidPop(stressWithLayer.Value.Data.Pop))); }
private static PersistableState Create(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, MacroStabilityInwardsExportStageType stageType, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { MacroStabilityInwardsSoilLayer2D[] layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfile.Layers).ToArray(); var statePoints = new List <PersistableStatePoint>(); if (PersistableStateHelper.HasValidStatePoints(soilProfile)) { statePoints.AddRange(layers.Where(l => l.Data.UsePop && PersistableStateHelper.HasValidPop(l.Data.Pop)) .Select(l => CreatePOPStatePoint(l, stageType, idFactory, registry)) .ToArray()); var preconsolidationStressPoints = new List <PersistableStatePoint>(); foreach (IMacroStabilityInwardsPreconsolidationStress preconsolidationStress in soilProfile.PreconsolidationStresses) { MacroStabilityInwardsSoilLayer2D layer = PersistableStateHelper.GetLayerForPreconsolidationStress(layers, preconsolidationStress); if (layer != null) { preconsolidationStressPoints.Add( CreateYieldStressStatePoint(layer, preconsolidationStress, stageType, idFactory, registry)); } } statePoints.AddRange(preconsolidationStressPoints); } var state = new PersistableState { Id = idFactory.Create(), StateLines = Enumerable.Empty <PersistableStateLine>(), StatePoints = statePoints }; registry.AddState(stageType, state.Id); return(state); }
public void Create_SoilProfileWithPOPAndPreconsolidationStressOnOneLayer_ReturnsPersistableStates() { // Setup MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] { MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)) }); IMacroStabilityInwardsSoilLayer firstLayer = stochasticSoilProfile.SoilProfile.Layers.First(); firstLayer.Data.UsePop = true; firstLayer.Data.Pop = new VariationCoefficientLogNormalDistribution { Mean = (RoundedDouble)1, CoefficientOfVariation = (RoundedDouble)2 }; calculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile; IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine; var idFactory = new IdFactory(); var registry = new MacroStabilityInwardsExportRegistry(); PersistableGeometryFactory.Create(soilProfile, idFactory, registry); // Call IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry); // Assert Assert.AreEqual(1, states.Count()); PersistableState state = states.First(); Assert.IsNotNull(state.Id); CollectionAssert.IsEmpty(state.StateLines); CollectionAssert.IsEmpty(state.StatePoints); }
/// <summary> /// Asserts whether <paramref name="actual"/> corresponds to <paramref name="soilProfileUnderSurface"/>, /// <paramref name="expectedName"/> and <paramref name="mapDataShouldContainAreas"/>. /// </summary> /// <param name="soilProfileUnderSurface">The <see cref="IMacroStabilityInwardsSoilProfileUnderSurfaceLine"/> /// that should be represented as series in <paramref name="actual"/>.</param> /// <param name="expectedName">The expected name of <paramref name="actual"/>.</param> /// <param name="mapDataShouldContainAreas">Indicator whether areas should be present.</param> /// <param name="actual">The actual <see cref="ChartData"/>.</param> /// <exception cref="AssertionException">Thrown when <paramref name="actual"/> does not correspond /// to <paramref name="soilProfileUnderSurface"/>, <paramref name="expectedName"/> or /// <paramref name="mapDataShouldContainAreas"/>.</exception> public static void AssertSoilProfileChartData(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfileUnderSurface, string expectedName, bool mapDataShouldContainAreas, ChartData actual) { Assert.IsInstanceOf <ChartDataCollection>(actual); var soilProfileChartData = (ChartDataCollection)actual; MacroStabilityInwardsSoilLayer2D[] layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(soilProfileUnderSurface?.Layers).ToArray(); int expectedLayerCount = layers.Length; Assert.AreEqual(expectedLayerCount, soilProfileChartData.Collection.Count()); Assert.AreEqual(expectedName, soilProfileChartData.Name); for (var i = 0; i < expectedLayerCount; i++) { var chartMultipleAreaData = soilProfileChartData.Collection.ElementAt(i) as ChartMultipleAreaData; Assert.IsNotNull(chartMultipleAreaData); Assert.AreEqual(layers.ElementAt(i).Data.MaterialName, chartMultipleAreaData.Name); Assert.AreEqual(mapDataShouldContainAreas, chartMultipleAreaData.Areas.Any()); } }
/// <summary> /// Creates a collection of <see cref="PersistableSoilLayerCollection"/>. /// </summary> /// <param name="soilProfile">The soil profile to use.</param> /// <param name="idFactory">The factory for creating IDs.</param> /// <param name="registry">The persistence registry.</param> /// <returns>A collection of <see cref="PersistableSoilLayerCollection"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter /// is <c>null</c>.</exception> public static IEnumerable <PersistableSoilLayerCollection> Create(IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile, IdFactory idFactory, MacroStabilityInwardsExportRegistry registry) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } if (idFactory == null) { throw new ArgumentNullException(nameof(idFactory)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } return(new[] { CreateSoilLayerCollection(soilProfile, MacroStabilityInwardsExportStageType.Daily, idFactory, registry), CreateSoilLayerCollection(soilProfile, MacroStabilityInwardsExportStageType.Extreme, idFactory, registry) }); }