/// <summary>
        /// Transforms the generic <paramref name="preconsolidationStress"/> into
        /// a <see cref="MacroStabilityInwardsPreconsolidationStress"/>.
        /// </summary>
        /// <param name="preconsolidationStress">The preconsolidation stress to use
        /// in the transformation.</param>
        /// <returns>A <see cref="MacroStabilityInwardsPreconsolidationStress"/>
        /// based on the given data.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="preconsolidationStress"/>
        /// is <c>null</c>.</exception>
        /// <exception cref="ImportedDataTransformException">Thrown when the
        /// <paramref name="preconsolidationStress"/> could not be transformed into
        /// a <see cref="MacroStabilityInwardsPreconsolidationStress"/>.</exception>
        public static MacroStabilityInwardsPreconsolidationStress Transform(PreconsolidationStress preconsolidationStress)
        {
            if (preconsolidationStress == null)
            {
                throw new ArgumentNullException(nameof(preconsolidationStress));
            }

            var location = new Point2D(preconsolidationStress.XCoordinate,
                                       preconsolidationStress.ZCoordinate);

            try
            {
                DistributionHelper.ValidateLogNormalDistribution(preconsolidationStress.StressDistributionType,
                                                                 preconsolidationStress.StressShift);

                var distribution = new VariationCoefficientLogNormalDistribution
                {
                    Mean = (RoundedDouble)preconsolidationStress.StressMean,
                    CoefficientOfVariation = (RoundedDouble)preconsolidationStress.StressCoefficientOfVariation
                };

                return(new MacroStabilityInwardsPreconsolidationStress(location, distribution));
            }
            catch (Exception e) when(e is DistributionValidationException || e is ArgumentOutOfRangeException)
            {
                string errorMessage = CreateErrorMessage(location, e.Message);

                throw new ImportedDataTransformException(errorMessage, e);
            }
            catch (ArgumentException e)
            {
                throw new ImportedDataTransformException(e.Message, e);
            }
        }
Пример #2
0
        public void ValidateLogNormalDistribution_DistributionTypeNull_DoesNotThrowException()
        {
            // Setup
            var    random = new Random(21);
            double shift  = random.NextDouble();

            // Call
            TestDelegate call = () => DistributionHelper.ValidateLogNormalDistribution(null, shift);

            // Assert
            Assert.DoesNotThrow(call);
        }
Пример #3
0
        public void ValidateLogNormalDistribution_ValidDistribution_DoesNotThrowException()
        {
            // Setup
            const long   distributionType = SoilLayerConstants.LogNormalDistributionValue;
            const double shift            = 0;

            // Call
            TestDelegate call = () => DistributionHelper.ValidateLogNormalDistribution(distributionType, shift);

            // Assert
            Assert.DoesNotThrow(call);
        }
 /// <summary>
 /// Validates the distribution properties of a parameter which is defined as a
 /// log normal distribution.
 /// </summary>
 /// <param name="soilLayerName">The name of the soil layer.</param>
 /// <param name="distributionType">The distribution type of the parameter.</param>
 /// <param name="shift">The shift of the parameter.</param>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <exception cref="ImportedDataTransformException">Thrown when the distribution properties are invalid.</exception>
 private static void ValidateStochasticLogNormalDistributionParameter(string soilLayerName,
                                                                      long?distributionType,
                                                                      double shift,
                                                                      string parameterName)
 {
     try
     {
         DistributionHelper.ValidateLogNormalDistribution(
             distributionType,
             shift);
     }
     catch (DistributionValidationException e)
     {
         string errorMessage = CreateErrorMessageForParameter(soilLayerName, parameterName, e.Message);
         throw new ImportedDataTransformException(errorMessage, e);
     }
 }
Пример #5
0
        public void ValidateLogNormalDistribution_ShiftNonZero_ThrowsDistributionValidationException()
        {
            // Setup
            const long distributionType = SoilLayerConstants.LogNormalDistributionValue;

            var    random = new Random(21);
            double shift  = random.NextDouble();

            // Call
            TestDelegate call = () => DistributionHelper.ValidateLogNormalDistribution(distributionType,
                                                                                       shift);

            // Assert
            var exception = Assert.Throws <DistributionValidationException>(call);

            Assert.AreEqual("Parameter moet lognormaal verdeeld zijn met een verschuiving gelijk aan 0.", exception.Message);
        }
Пример #6
0
        public void ValidateLogNormalDistribution_InvalidDistributionType_ThrowsDistributionValidationException()
        {
            // Setup
            const long distributionType = -1;

            var    random = new Random(21);
            double shift  = random.NextDouble();

            // Call
            TestDelegate call = () => DistributionHelper.ValidateLogNormalDistribution(distributionType,
                                                                                       shift);

            // Assert
            var exception = Assert.Throws <DistributionValidationException>(call);

            Assert.AreEqual("Parameter moet lognormaal verdeeld zijn.", exception.Message);
        }