using System; namespace Ringtoets.Piping.Data.Probabilistics { /// /// This class defines a design variable for a lognormal distribution. /// public class LognormalDistributionDesignVariable : DesignVariable { /// /// Initializes a new instance of the class. /// /// A lognormal distribution. public LognormalDistributionDesignVariable(LognormalDistribution distribution) : base(distribution) {} public override double GetDesignValue() { var normalSpaceDesignValue = DetermineDesignValueInNormalDistributionSpace(); return ProjectFromNormalToLognormalSpace(normalSpaceDesignValue); } /// /// Projects into 'normal /// distribution' space and calculates the design value for that value space. /// /// The design value in 'normal distribution' space. /// Design values can only be determined in 'normal distribution' space. private double DetermineDesignValueInNormalDistributionSpace() { var normalDistribution = CreateNormalDistributionFromLognormalDistribution(); var normalDistributionDesignVariable = new NormalDistributionDesignVariable(normalDistribution) { Percentile = Percentile }; return normalDistributionDesignVariable.GetDesignValue(); } private static double ProjectFromNormalToLognormalSpace(double normalSpaceDesignValue) { return Math.Exp(normalSpaceDesignValue); } /// /// Determine normal distribution parameters from log-normal parameters, as /// design value can only be determined in 'normal distribution' space. /// Below formula's come from Tu-Delft College dictaat "b3 Probabilistisch Ontwerpen" /// by ir. A.C.W.M. Vrouwenvelder and ir.J.K. Vrijling 5th reprint 1987. /// /// A normal distribution based on the parameters of . private NormalDistribution CreateNormalDistributionFromLognormalDistribution() { double sigmaLogOverMuLog = Distribution.StandardDeviation / Distribution.Mean; double sigmaNormal = Math.Sqrt(Math.Log(sigmaLogOverMuLog * sigmaLogOverMuLog + 1.0)); double muNormal = Math.Log(Distribution.Mean) - 0.5 * sigmaNormal * sigmaNormal; return new NormalDistribution { Mean = muNormal, StandardDeviation = sigmaNormal }; } } }