//----------------------------------------------------------------------- // // Copyright (c) 2010 Deltares. All rights reserved. // // B.S.T.I.M. The // tom.the@deltares.nl // 18-05-2010 // Segment data //----------------------------------------------------------------------- using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; namespace Deltares.Dam.Data { using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; public class SoilGeometryProbability : IComparable { public virtual SoilProfile1D SoilProfile { get; set; } public virtual string SoilGeometry2DName { get; set; } public virtual SoilProfile2D SoilProfile2D { get; set; } public virtual FailureMechanismSystemType? SegmentFailureMechanismType { get; set; } public virtual double Probability { get; set; } // Probability of occurance; number between 0.0 and 100.0 /// /// Assigns the specified soil geometry probability. /// /// The soil geometry probability. public void Assign(SoilGeometryProbability soilGeometryProbability) { if (soilGeometryProbability.SoilProfile != null) { SoilProfile = new SoilProfile1D(); SoilProfile.Assign(soilGeometryProbability.SoilProfile); } SegmentFailureMechanismType = soilGeometryProbability.SegmentFailureMechanismType; Probability = soilGeometryProbability.Probability; SoilGeometry2DName = soilGeometryProbability.SoilGeometry2DName; } public SoilGeometryType SoilGeometryType { get { if (SoilProfile != null) { return SoilGeometryType.SoilGeometry1D; } else { if (SoilGeometry2DName == null) { throw new TimeSerieStabilityCalculatorException("No soilprofile assigned"); } return SoilGeometryType.SoilGeometry2D; } } } /// /// Returns either the 1D-geometry or the 2D-geometry name /// public virtual string SoilGeometryName { get { string soilGeometryName = ""; if (this.SoilProfile != null) { soilGeometryName = this.SoilProfile.Name; } else { soilGeometryName = this.SoilGeometry2DName; } return soilGeometryName; } } public int CompareTo(SoilGeometryProbability other) { return - this.Probability.CompareTo(other.Probability); } } public class Segment { private List soilGeometryProbabilities = new List(); public virtual string Name { get; set; } /// /// Gets the soil probalilities for this segment /// public virtual List SoilProfileProbabilities { get { return this.soilGeometryProbabilities; } } public SoilProfile1D GetMostProbableProfile(FailureMechanismSystemType? segmentFailureMechanismType) { IEnumerable spps = from SoilGeometryProbability spp in this.soilGeometryProbabilities where !spp.SegmentFailureMechanismType.HasValue || !segmentFailureMechanismType.HasValue || spp.SegmentFailureMechanismType == segmentFailureMechanismType orderby spp.Probability descending select spp; if (spps.Count() > 0) return spps.First().SoilProfile; else return null; } public string GetMostProbableGeometry2DName(FailureMechanismSystemType? segmentFailureMechanismType) { IEnumerable spps = from SoilGeometryProbability spp in this.soilGeometryProbabilities where !spp.SegmentFailureMechanismType.HasValue || !segmentFailureMechanismType.HasValue || spp.SegmentFailureMechanismType == segmentFailureMechanismType orderby spp.Probability descending select spp; if (spps.Count() > 0) return spps.First().SoilGeometry2DName; else return null; } public void AddSoilProfileProbability(SoilProfile1D soilProfile, double probability, FailureMechanismSystemType? segmentFailureMechanismType) { if (this.soilGeometryProbabilities.Where(x => x.SoilProfile == soilProfile && x.SegmentFailureMechanismType == segmentFailureMechanismType).Count() == 0) this.soilGeometryProbabilities.Add(new SoilGeometryProbability() { SoilProfile = soilProfile, Probability = probability, SegmentFailureMechanismType = segmentFailureMechanismType, SoilGeometry2DName = null }); } public double? GetSoilProfileProbability(SoilProfile1D soilProfile, FailureMechanismSystemType? segmentFailureMechanismType) { IEnumerable probs = this.soilGeometryProbabilities.Where( x => (x.SoilProfile == soilProfile) && (segmentFailureMechanismType == null || x.SegmentFailureMechanismType == segmentFailureMechanismType || x.SegmentFailureMechanismType == null)); if (probs.Count() > 0) return probs.Select(x => x.Probability).Average(); else return null; } public void AddSoilGeometry2DProbability(string soilGeometry2DName, double probability, FailureMechanismSystemType? segmentFailureMechanismType) { if (this.soilGeometryProbabilities.Where(x => x.SoilGeometry2DName == soilGeometry2DName && x.SegmentFailureMechanismType == segmentFailureMechanismType).Count() == 0) this.soilGeometryProbabilities.Add(new SoilGeometryProbability() { SoilProfile = null, Probability = probability, SegmentFailureMechanismType = segmentFailureMechanismType, SoilGeometry2DName = soilGeometry2DName }); } public double? GetSoilGeometry2DProbability(string soilGeometry2DName, FailureMechanismSystemType? segmentFailureMechanismType) { IEnumerable probs = this.soilGeometryProbabilities.Where( x => (x.SoilGeometry2DName == soilGeometry2DName) && (segmentFailureMechanismType == null || x.SegmentFailureMechanismType == segmentFailureMechanismType || x.SegmentFailureMechanismType == null)); if (probs.Count() > 0) return probs.Select(x => x.Probability).Average(); else return null; } public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(this.Name); sb.Append(": "); foreach (FailureMechanismSystemType type in Enum.GetValues(typeof(FailureMechanismSystemType))) { sb.Append(type.ToString()); sb.Append(": "); foreach (SoilGeometryProbability spp in this.SoilProfileProbabilities.Where(x => x.SegmentFailureMechanismType == null || x.SegmentFailureMechanismType == type)) { if (spp.SoilProfile != null) { sb.Append(String.Format("(1D) {0} ({1}%) ", spp.SoilProfile.Name, spp.Probability)); } else { sb.Append(String.Format("(2D) {0} ({1}%) ", spp.SoilGeometry2DName, spp.Probability)); } } } return sb.ToString(); } /// /// Assemble a list of key/value pairs with the relevant parameters for the specified 1d-profile /// /// public Dictionary GetParametersForSoilProfile1DAsNameValuePairs(string soilProfile1DId, FailureMechanismSystemType failureMechanismSystemType) { SoilGeometryProbability soilProfileProbability = this.SoilProfileProbabilities.FirstOrDefault(x => (x.SoilProfile != null && x.SoilProfile.Name.Equals(soilProfile1DId) && x.SegmentFailureMechanismType == failureMechanismSystemType )); if (soilProfileProbability != null) { var nameValuePairs = new Dictionary(); var numberFormatInfo = new NumberFormatInfo(); numberFormatInfo.NumberDecimalSeparator = "."; nameValuePairs.Add("Probability", soilProfileProbability.Probability.ToString(numberFormatInfo)); nameValuePairs.Add("FailureMechanismType", soilProfileProbability.SegmentFailureMechanismType.ToString()); return nameValuePairs; } else { return null; } } /// /// Assemble a list of key/value pairs with the relevant parameters for the specified 2d-profile /// /// public Dictionary GetParametersForSoilProfile2DAsNameValuePairs(string soilProfile2DId, FailureMechanismSystemType failureMechanismSystemType) { SoilGeometryProbability soilProfileProbability = this.SoilProfileProbabilities.FirstOrDefault(x => x.SoilGeometry2DName.Equals(soilProfile2DId) && x.SegmentFailureMechanismType == failureMechanismSystemType); if (soilProfileProbability != null) { var nameValuePairs = new Dictionary(); var numberFormatInfo = new NumberFormatInfo(); numberFormatInfo.NumberDecimalSeparator = "."; nameValuePairs.Add("Probability", soilProfileProbability.Probability.ToString(numberFormatInfo)); nameValuePairs.Add("FailureMechanismType", soilProfileProbability.SegmentFailureMechanismType.ToString()); return nameValuePairs; } else { return null; } } } }