using System; using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; using Deltares.Probabilistic; using Deltares.Standard; namespace Deltares.Stability { /// /// Handles transformation between measured and design values /// public class StabilityTransformer : ITransformer { private StabilityModel stabilityModel = null; private StabilitySettings stabilitySettings = null; public StabilityTransformer() {} public StabilitySettings StabilitySettings { get { return stabilitySettings; } set { stabilitySettings = value; } } public StabilityModel StabilityModel { get { return stabilityModel; } set { stabilityModel = value; } } public double GetTransformedValue(object owner, string property, double defaultValue) { if (owner is Soil) { var soil = (Soil) owner; Stochast stochast = GetStochast(soil, property); if (stochast != null) { return GetDesignFromMean(stochast, GetDesignFactor(stochast)); } else { return defaultValue; } } else if (owner is StabilityDikeLocationInfo) { var location = (StabilityDikeLocationInfo) owner; } else if (owner is PreConsolidationStress) { switch (property) { case "StressValue": return ((PreConsolidationStress) owner).StressStochast.GetXFromP(0.05)/GetPreconsolidationStressFactor(); } } return defaultValue; } public double SetTransformedValue(object owner, string property, double transformedValue) { if (owner is Soil) { var soil = (Soil) owner; Stochast stochast = GetStochast(soil, property); if (stochast != null) { stochast.Mean = GetMeanFromDesign(stochast, GetDesignFactor(stochast), transformedValue); return stochast.Mean; } } else if (owner is StabilityDikeLocationInfo) { var location = (StabilityDikeLocationInfo) owner; } return transformedValue; } // Private Declarations private Stochast GetStochast(Soil soil, string property) { switch (property) { case "Cohesion": return soil.CohesionStochast; case "FrictionAngle": return soil.FrictionAngleStochast; case "RRatio": return soil.RatioCuPcStochast; case "RatioCuPc": return soil.RatioCuPcStochast; case "RatioCuPcActve": return soil.RatioCuPcActiveStochast; case "RatioCuPcPassive": return soil.RatioCuPcPassiveStochast; case "CuTop": return soil.CuTopStochast; case "CuPassiveTop": return soil.CuPassiveTopStochast; case "CuActiveTop": return soil.CuActiveTopStochast; case "CuBottom": return soil.CuBottomStochast; case "CuPassiveBottom": return soil.CuPassiveBottomStochast; case "CuActiveBottom": return soil.CuActiveBottomStochast; case "CuGradient": return soil.CuGradientStochast; case "POP": return soil.POPStochast; default: return null; } } private double GetDesignFactor(Stochast stochast) { if (stochast.Owner is Soil) { var soil = (Soil) stochast.Owner; switch (stochast.AssociatedPropertyName) { case "RRatio": return soil.RRatioStochast.DesignFactor; case "RatioCuPc": return soil.RRatioStochast.DesignFactor; case "RatioCuPcActive": return soil.RRatioStochast.DesignFactor; case "RatioCuPcPassive": return soil.RRatioStochast.DesignFactor; case "CuTop": return soil.CuStochast.DesignFactor; case "CuPassiveTop": return soil.CuStochast.DesignFactor; case "CuActiveTop": return soil.CuStochast.DesignFactor; case "CuBottom": return soil.CuStochast.DesignFactor; case "CuPassiveBottom": return soil.CuStochast.DesignFactor; case "CuActiveBottom": return soil.CuStochast.DesignFactor; case "CuGradient": return soil.CuStochast.DesignFactor; default: return stochast.DesignFactor; } } else { return stochast.DesignFactor; } } private double GetPreconsolidationStressFactor() { if (stabilitySettings != null) { return stabilitySettings.PreconsolidationStressFactor; } else if (stabilityModel != null) { return stabilityModel.PreconsolidationStressModelFactor; } else { return 1; } } // ======================================================================================================================= // Date ID Modification // 2003-11-5 Best Created. // ======================================================================================================================= private double GetNormalDesignFromMean(double partialDesignFactor, double mean, double designStdDev, double variationCoefficient) { try { return (1/partialDesignFactor)*mean*(1 + (designStdDev*variationCoefficient)); } catch { return 0; } } // ======================================================================================================================= // Date ID Modification // 2003-11-5 Best Created. // ======================================================================================================================= private double GetLogNormalDesignFromMean(double partialDesignFactor, double mean, double designStdDev, double variationCoefficient) { try { double sigmaY = Math.Sqrt(Math.Log(1 + variationCoefficient*variationCoefficient)); double yMean = 0.5*Math.Log(mean*mean/(variationCoefficient*variationCoefficient + 1)); return (1/partialDesignFactor)*Math.Exp(yMean + designStdDev*sigmaY); } catch { return 0; } } // ======================================================================================================================= // Date ID Modification // 2003-11-5 Best Created. // ======================================================================================================================= private double GetDesignFromMean(Stochast stochast, double partialDesignFactor) { switch (stochast.DistributionType) { case DistributionType.Normal: return GetNormalDesignFromMean(partialDesignFactor, stochast.Mean, stochast.Deviation, stochast.Variation); case DistributionType.LogNormal: return GetLogNormalDesignFromMean(partialDesignFactor, stochast.Mean, stochast.Deviation, stochast.Variation); case DistributionType.Deterministic: return stochast.Mean/partialDesignFactor; default: return stochast.Mean/partialDesignFactor; } } // ======================================================================================================================= // Date ID Modification // 2003-11-5 Best Created. // ======================================================================================================================= private double GetMeanFromDesign(Stochast stochast, double partialDesignFactor, double designValue) { switch (stochast.DistributionType) { case DistributionType.Normal: return GetNormalMeanFromDesign(partialDesignFactor, designValue, stochast.Deviation, stochast.Variation); case DistributionType.LogNormal: return GetLogNormalMeanFromDesign(partialDesignFactor, designValue, stochast.Deviation, stochast.Variation); case DistributionType.Deterministic: return designValue*partialDesignFactor; default: return designValue*partialDesignFactor; } } // ======================================================================================================================= // Date ID Modification // 2003-11-5 Best Created. // ======================================================================================================================= private double GetNormalMeanFromDesign(double partialDesignFactor, double designValue, double designStdDev, double stdDev) { try { double partial = 1/partialDesignFactor; return (designValue - (partial*designStdDev*stdDev))/partial; } catch { return 0; } } // ======================================================================================================================= // Date ID Modification // 2003-11-5 Best Created. // ======================================================================================================================= private double GetLogNormalMeanFromDesign(double partialDesignFactor, double designValue, double designStdDev, double stdDev) { try { double partial = 1/partialDesignFactor; double xMeanOld = designValue - partial*designStdDev*stdDev; int loopCount = 0; double xMeanNew; bool ready = false; do { double vx = stdDev/xMeanOld; double sigmaY = Math.Sqrt(Math.Log(1 + vx*vx)); double yMean = Math.Log(designValue/partial) - designStdDev*sigmaY; xMeanNew = Math.Exp(yMean + 0.5*sigmaY*sigmaY); ready = (Math.Abs(xMeanOld - xMeanNew) < 0.001*designValue); xMeanOld = xMeanNew; loopCount++; } while (!(ready || (loopCount > 20))); return xMeanNew; } catch { return 0; } } } }