Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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>
        /// 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));
            }
        }
        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);
        }
Esempio n. 5
0
        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);
        }
        public void Create_WithValidData_ReturnsStages()
        {
            // Setup
            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            var stageTypes = new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            };

            var settingsList   = new List <PersistableCalculationSettings>();
            var geometryList   = new List <PersistableGeometry>();
            var soilLayersList = new List <PersistableSoilLayerCollection>();
            var waternetList   = new List <PersistableWaternet>();
            var waternetCreatorSettingsList = new List <PersistableWaternetCreatorSettings>();
            var stateList = new List <PersistableState>();

            foreach (MacroStabilityInwardsExportStageType stageType in stageTypes)
            {
                var settings = new PersistableCalculationSettings
                {
                    Id = idFactory.Create()
                };
                settingsList.Add(settings);

                var geometry = new PersistableGeometry
                {
                    Id = idFactory.Create()
                };
                geometryList.Add(geometry);

                var persistableSoilLayerCollection = new PersistableSoilLayerCollection
                {
                    Id = idFactory.Create()
                };
                soilLayersList.Add(persistableSoilLayerCollection);

                var waternet = new PersistableWaternet
                {
                    Id = idFactory.Create()
                };
                waternetList.Add(waternet);

                var waternetCreatorSettings = new PersistableWaternetCreatorSettings
                {
                    Id = idFactory.Create()
                };
                waternetCreatorSettingsList.Add(waternetCreatorSettings);

                var state = new PersistableState
                {
                    Id = idFactory.Create()
                };
                stateList.Add(state);

                registry.AddSettings(stageType, settings.Id);
                registry.AddGeometry(stageType, geometry.Id);
                registry.AddSoilLayer(stageType, persistableSoilLayerCollection.Id);
                registry.AddWaternet(stageType, waternet.Id);
                registry.AddWaternetCreatorSettings(stageType, waternetCreatorSettings.Id);
                registry.AddState(stageType, state.Id);
            }

            // Call
            IEnumerable <PersistableStage> stages = PersistableStageFactory.Create(idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertStages(stages, settingsList, geometryList, soilLayersList, waternetList, waternetCreatorSettingsList, stateList);
        }
Esempio n. 7
0
 /// <summary>
 /// Sets the persistable state of the current instance
 /// </summary>
 /// <param name="persistableState"></param>
 public void SetState(PersistableState persistableState)
 {
     this.State = persistableState;
 }
Esempio n. 8
0
 /// <summary>
 /// Instantiates the Controls.Types.Persistable class
 /// </summary>
 /// <param name="state">Object state</param>
 /// <param name="version">Version number of the object</param>
 public Persistable(PersistableState state, int?version)
 {
     this.State             = state;
     this.Version           = version;
     this.compositesIndexer = new Dictionary <string, dynamic>();
 }