Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="MacroStabilityInwardsSoilProfileUnderSurfaceLine"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile containing layers under the <paramref name="surfaceLine"/>.</param>
        /// <param name="surfaceLine">The surface line which determines the top of the <paramref name="soilProfile"/>.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsSoilProfileUnderSurfaceLine"/> containing geometries from the
        /// <paramref name="soilProfile"/> under the <paramref name="surfaceLine"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="NotSupportedException">Thrown when the given <paramref name="soilProfile"/> type
        /// is not supported.</exception>
        public static MacroStabilityInwardsSoilProfileUnderSurfaceLine Create(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile,
                                                                              MacroStabilityInwardsSurfaceLine surfaceLine)
        {
            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            if (surfaceLine == null)
            {
                throw new ArgumentNullException(nameof(surfaceLine));
            }

            var profile1D = soilProfile as MacroStabilityInwardsSoilProfile1D;

            if (profile1D != null)
            {
                return(Create(profile1D, surfaceLine));
            }

            var profile2D = soilProfile as MacroStabilityInwardsSoilProfile2D;

            if (profile2D != null)
            {
                return(Create(profile2D));
            }

            throw new NotSupportedException($"{soilProfile.GetType().Name} is not supported. " +
                                            $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} " +
                                            $"and {nameof(MacroStabilityInwardsSoilProfile2D)}.");
        }
        /// <summary>
        /// Adds the entity representation of <paramref name="soilProfile"/> to the <paramref name="entity"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile to store.</param>
        /// <param name="entity">The entity to update.</param>
        /// <param name="registry">The registry to use for persisting entities.</param>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="soilProfile"/> is
        /// not of type <see cref="MacroStabilityInwardsSoilProfile1D"/> or <see cref="MacroStabilityInwardsSoilProfile2D"/>.</exception>
        private static void AddEntityForProfile(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile,
                                                MacroStabilityInwardsStochasticSoilProfileEntity entity,
                                                PersistenceRegistry registry)
        {
            var soilProfile1D = soilProfile as MacroStabilityInwardsSoilProfile1D;

            if (soilProfile1D != null)
            {
                entity.MacroStabilityInwardsSoilProfileOneDEntity = soilProfile1D.Create(registry);
                return;
            }

            var soilProfile2D = soilProfile as MacroStabilityInwardsSoilProfile2D;

            if (soilProfile2D != null)
            {
                entity.MacroStabilityInwardsSoilProfileTwoDEntity = soilProfile2D.Create(registry);
                return;
            }

            string exceptionMessage = $"{soilProfile.GetType().Name} is not supported. " +
                                      $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} and {nameof(MacroStabilityInwardsSoilProfile2D)}.";

            throw new NotSupportedException(exceptionMessage);
        }
 /// <summary>
 /// Updates the name of <paramref name="chartData"/> based on <paramref name="soilProfile"/>.
 /// </summary>
 /// <param name="chartData">The <see cref="ChartDataCollection"/> to update the name for.</param>
 /// <param name="soilProfile">The <see cref="IMacroStabilityInwardsSoilProfile{T}"/> used for obtaining the name.</param>
 /// <remarks>A default name is set when <paramref name="soilProfile"/> is <c>null</c>.</remarks>
 public static void UpdateSoilProfileChartDataName(ChartDataCollection chartData,
                                                   IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile)
 {
     chartData.Name = soilProfile != null
                          ? soilProfile.Name
                          : RiskeerCommonFormsResources.StochasticSoilProfileProperties_DisplayName;
 }
        public void Read_WithCollectorAnd2dProfile_ReturnsStochasticSoilProfileWithPropertiesSet()
        {
            // Setup
            var random = new Random(21);
            var entity = new MacroStabilityInwardsStochasticSoilProfileEntity
            {
                Probability = random.NextDouble(),
                MacroStabilityInwardsSoilProfileTwoDEntity = new MacroStabilityInwardsSoilProfileTwoDEntity
                {
                    Name = "SoilProfile",
                    MacroStabilityInwardsSoilLayerTwoDEntities =
                    {
                        MacroStabilityInwardsSoilLayerTwoDEntityTestFactory.CreateMacroStabilityInwardsSoilLayerTwoDEntity()
                    }
                }
            };
            var collector = new ReadConversionCollector();

            // Call
            MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = entity.Read(collector);

            // Assert
            Assert.IsNotNull(stochasticSoilProfile);
            Assert.AreEqual(entity.Probability, stochasticSoilProfile.Probability, 1e-6);

            IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> profile = stochasticSoilProfile.SoilProfile;

            Assert.IsInstanceOf <MacroStabilityInwardsSoilProfile2D>(profile);
            Assert.AreEqual(entity.MacroStabilityInwardsSoilProfileTwoDEntity.Name, profile.Name);
        }
Esempio n. 5
0
        private void UpdateInputChartData()
        {
            MacroStabilityInwardsInput       input       = data.InputParameters;
            MacroStabilityInwardsSurfaceLine surfaceLine = input.SurfaceLine;
            IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile = input.StochasticSoilProfile?.SoilProfile;

            if (!ReferenceEquals(currentSoilProfile, soilProfile) || !ReferenceEquals(currentSurfaceLine, surfaceLine))
            {
                currentSoilProfile = soilProfile;
                currentSurfaceLine = surfaceLine;

                SetSoilProfileChartData();
            }

            SetWaternetExtremeChartData(DerivedMacroStabilityInwardsInput.GetWaternetExtreme(input, generalInput, GetEffectiveAssessmentLevel()));
            SetWaternetDailyChartData(DerivedMacroStabilityInwardsInput.GetWaternetDaily(input, generalInput));

            if (data.Output != null)
            {
                SetSurfaceLineChartData(surfaceLine);
                SetSoilLayerAreas();
                SetWaternetDatas(surfaceLine);
            }
            else
            {
                SetSurfaceLineChartData(null);
                SetEmptySoilLayerAreas();
                SetEmptyWaternets();
            }

            soilProfileChartData.Collection.ForEachElementDo(sp => sp.NotifyObservers());
            waternetZonesDailyChartData.Collection.ForEachElementDo(cd => cd.NotifyObservers());
            waternetZonesExtremeChartData.Collection.ForEachElementDo(cd => cd.NotifyObservers());
        }
        private static bool IsSame(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile,
                                   IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> otherSoilProfile)
        {
            bool equalNames = soilProfile.Name.Equals(otherSoilProfile.Name);
            bool equalTypes = soilProfile.GetType() == otherSoilProfile.GetType();

            return(equalNames && equalTypes);
        }
Esempio n. 7
0
        private void SetSoilProfileChartData(MacroStabilityInwardsSurfaceLine surfaceLine,
                                             IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile)
        {
            if (!ReferenceEquals(currentSoilProfile, soilProfile) || !SurfaceLineEqual(surfaceLine))
            {
                SetSoilProfileChartData();
            }

            SetSoilLayerAreas();
        }
        /// <summary>
        /// Creates a new instance of <see cref="MacroStabilityInwardsStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="probability">Probability of the stochastic soil profile.</param>
        /// <param name="soilProfile">The soil profile.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/>
        /// is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="probability"/>
        /// is outside the range [0, 1].</exception>
        public MacroStabilityInwardsStochasticSoilProfile(double probability, IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile)
        {
            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            Probability = probability;
            SoilProfile = soilProfile;
        }
Esempio n. 9
0
        private void SetChartData()
        {
            MacroStabilityInwardsInput       macroStabilityInwardsInput = data.InputParameters;
            MacroStabilityInwardsSurfaceLine surfaceLine = macroStabilityInwardsInput.SurfaceLine;
            IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile = macroStabilityInwardsInput.StochasticSoilProfile?.SoilProfile;

            hydraulicLocationCalculationObserver.Observable = getHydraulicBoundaryLocationCalculationFunc();

            SetSurfaceLineChartData(surfaceLine);
            SetSoilProfileChartData(surfaceLine, soilProfile);

            SetWaternetExtremeChartData(DerivedMacroStabilityInwardsInput.GetWaternetExtreme(macroStabilityInwardsInput, generalInput, GetEffectiveAssessmentLevel()), surfaceLine);
            SetWaternetDailyChartData(DerivedMacroStabilityInwardsInput.GetWaternetDaily(macroStabilityInwardsInput, generalInput), surfaceLine);

            MacroStabilityInwardsGridDeterminationType gridDeterminationType = macroStabilityInwardsInput.GridDeterminationType;
            MacroStabilityInwardsGrid leftGrid  = macroStabilityInwardsInput.LeftGrid;
            MacroStabilityInwardsGrid rightGrid = macroStabilityInwardsInput.RightGrid;

            leftGridChartData.Points  = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(leftGrid, gridDeterminationType);
            rightGridChartData.Points = MacroStabilityInwardsChartDataPointsFactory.CreateGridPoints(rightGrid, gridDeterminationType);

            tangentLinesData.Lines = MacroStabilityInwardsChartDataPointsFactory.CreateTangentLines(macroStabilityInwardsInput.GridDeterminationType,
                                                                                                    macroStabilityInwardsInput.TangentLineDeterminationType,
                                                                                                    macroStabilityInwardsInput.TangentLineZBottom,
                                                                                                    macroStabilityInwardsInput.TangentLineZTop,
                                                                                                    macroStabilityInwardsInput.TangentLineNumber,
                                                                                                    macroStabilityInwardsInput.SurfaceLine);

            currentSoilProfile = soilProfile;
            if (surfaceLine != null)
            {
                if (currentSurfaceLine == null)
                {
                    currentSurfaceLine = new MacroStabilityInwardsSurfaceLine(surfaceLine.Name);
                }

                currentSurfaceLine.CopyProperties(surfaceLine);
            }
            else
            {
                currentSurfaceLine = null;
            }
        }
        /// <summary>
        /// Transforms the generic <paramref name="stochasticSoilProfile"/> into
        /// <see cref="MacroStabilityInwardsStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="stochasticSoilProfile">The stochastic soil profile to use
        /// in the transformation.</param>
        /// <param name="soilProfile">The transformed soil profile.</param>
        /// <returns>A new <paramref name="soilProfile"/> based on the given data.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="ImportedDataTransformException">Thrown when <see cref="StochasticSoilProfile"/>
        /// could not be transformed.</exception>
        public static MacroStabilityInwardsStochasticSoilProfile Transform(StochasticSoilProfile stochasticSoilProfile,
                                                                           IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile)
        {
            if (stochasticSoilProfile == null)
            {
                throw new ArgumentNullException(nameof(stochasticSoilProfile));
            }

            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            try
            {
                return(new MacroStabilityInwardsStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile));
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new ImportedDataTransformException(e.Message, e);
            }
        }
Esempio n. 11
0
        public void GivenCreatedEntity_WhenCreateCalledOnSameObject_ThenSameEntityInstanceReturned(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile)
        {
            // Given
            var stochasticSoilProfile = new MacroStabilityInwardsStochasticSoilProfile(0.4, soilProfile);
            var registry = new PersistenceRegistry();

            MacroStabilityInwardsStochasticSoilProfileEntity entity1 = stochasticSoilProfile.Create(registry, 0);

            // When
            MacroStabilityInwardsStochasticSoilProfileEntity entity2 = stochasticSoilProfile.Create(registry, 0);

            // Then
            Assert.AreSame(entity1, entity2);
        }