// Copyright (C) Stichting Deltares 2023. 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 Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Standard.Language; namespace Deltares.DamEngine.Data.Geotechnics { /// /// 1D Soil Layer Object /// public class SoilLayer1D : SoilLayer, ISoilProfileProvider, ICloneable, IComparable { /// /// Function delegate to get layer above/beneath via the 1D Profile /// /// The layer. /// protected delegate SoilLayer1D LayerGetFunction(SoilLayer1D layer); private SoilProfile1D soilProfile; private double topLevel; /// /// Initializes a new instance of the class. /// public SoilLayer1D() { Name = LocalizationManager.GetTranslatedText(this, "DefaultNameSoilLayer1D"); } /// /// Initializes a new instance of the class, using given soil and topLevel. /// /// The soil. /// The top level. public SoilLayer1D(Soil soil, double topLevel) : this() { Soil = soil; this.topLevel = topLevel; } /// /// Gets or sets the toplevel of the layer /// public virtual double TopLevel { get { return topLevel; } set { // don't do anything if top is already value if (Math.Abs(value - topLevel) > GeometryConstants.Accuracy) { topLevel = value; } } } /// /// Gets or sets the bottom level of the layer /// /// /// The bottom level. /// public virtual double BottomLevel { get { return SoilProfile == null ? 0d : SoilProfile.GetBottomLevel(this); } set { // don't do anything if bottom is already value if (Math.Abs(value - BottomLevel) > GeometryConstants.Accuracy) { var layerBelow = LayerBelow(); if (layerBelow != null) { layerBelow.topLevel = value; } else if (SoilProfile != null) { SoilProfile.BottomLevel = value; } if (SoilProfile != null && value < SoilProfile.BottomLevel) { SoilProfile.BottomLevel = value; } } } } /// /// Gets the distance between bottom and top. /// /// /// The height. /// [Translation("LayerHeight")] public double Height { get { return TopLevel - BottomLevel; } } /// Gets or sets the soil profile. /// The soil profile is set automatically by the soil layers list in SoilProfile1D public SoilProfile1D SoilProfile { get { return soilProfile; } set { soilProfile = value; } } /// /// Clones this instance. /// /// Clone of this instance public virtual object Clone() { var clone = new SoilLayer1D(); clone.Assign(this); return clone; } /// /// Returns the Layer below. /// /// layer below private SoilLayer1D LayerBelow() { return SoilProfile.GetLayerBelow(this); } /// /// Assigns the specified layer. /// /// The layer. public void Assign(SoilLayer1D layer) { Name = layer.Name; TopLevel = layer.TopLevel; Soil = layer.Soil; IsAquifer = layer.IsAquifer; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return Name; } /// /// Sorting will be applied by the mot uplift layer first /// /// Other soil layer /// Comparable indication public int CompareTo(SoilLayer1D other) { return - TopLevel.CompareTo(other.TopLevel); } } }