// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Deltares.DamEngine.Data.Geotechnics; namespace Deltares.DamEngine.Data.General { /// /// Class holding all soilprofiles (1D/2D) and their probabilities as segment. /// public class Segment { private readonly List soilGeometryProbabilities = new List(); /// /// Gets or sets the name. /// /// /// The name. /// public virtual string Name { get; set; } /// /// Gets the soil probalilities for this segment /// public virtual List SoilProfileProbabilities { get { return this.soilGeometryProbabilities; } } /// /// Gets the most probable profile1D. /// /// Type of the segment failure mechanism. /// public SoilProfile1D GetMostProbableProfile1D(SegmentFailureMechanismType? segmentFailureMechanismType) { var mostProbableSoilGeometryProbability = GetMostProbableSoilGeometryProbability(segmentFailureMechanismType); if (mostProbableSoilGeometryProbability != null && mostProbableSoilGeometryProbability.SoilProfileType == SoilProfileType.ProfileType1D) { return mostProbableSoilGeometryProbability?.SoilProfile1D; } else { return null; } } /// /// Gets the name of the most probable sti filename (name of MStab .sti file). /// /// Type of the segment failure mechanism. /// public string GetMostProbableProfile2DStiFileName(SegmentFailureMechanismType? segmentFailureMechanismType) { var mostProbableSoilGeometryProbability = GetMostProbableSoilGeometryProbability(segmentFailureMechanismType); if (mostProbableSoilGeometryProbability != null && mostProbableSoilGeometryProbability.SoilProfileType == SoilProfileType.ProfileTypeStiFile) { return mostProbableSoilGeometryProbability?.FullStiFileName; } else { return null; } } /// /// Gets the most probable soil geometry probability. /// /// Type of the segment failure mechanism. /// public SoilGeometryProbability GetMostProbableSoilGeometryProbability(SegmentFailureMechanismType? 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.Any()) return spps.First(); else return null; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(this.Name); sb.Append(": "); foreach (SegmentFailureMechanismType type in Enum.GetValues(typeof(SegmentFailureMechanismType))) { sb.Append(type.ToString()); sb.Append(": "); foreach (SoilGeometryProbability spp in this.SoilProfileProbabilities.Where(x => x.SegmentFailureMechanismType == null || x.SegmentFailureMechanismType == type)) { if (spp.SoilProfile1D != null) { sb.Append(String.Format("(1D) {0} ({1}%) ", spp.SoilProfile1D.Name, spp.Probability)); } else { sb.Append(String.Format("(2D) {0} ({1}%) ", spp.StiFileName, spp.Probability)); } //#Bka: should be adapted for WtiStability where 2D profiles are used. } } return sb.ToString(); } } }