// Copyright (C) Stichting Deltares 2021. 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 Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Standard.Language; using Deltares.DamEngine.Data.Standard.Validation; namespace Deltares.DamEngine.Data.Geotechnics { /// /// 2D Soil Profile Object /// public class SoilProfile2D : SoilProfile { protected GeometryData geometry = new GeometryData(); protected readonly List surfaces = new List(); /// /// Initializes a new instance of the class. /// public SoilProfile2D() { Name = LocalizationManager.GetTranslatedText(this, "DefaultNameSoilProfile2D"); } /// /// Gets the surfaces. /// /// /// The surfaces. /// [Validate] public virtual IList Surfaces { get { return surfaces; } } /// /// Gets or sets the geometry. /// /// /// The geometry. /// public GeometryData Geometry { get { return geometry; } set { geometry = value; } } /// /// Gets the soil profile 1D at the given X. /// /// The x. /// Soil Profile 1D public virtual SoilProfile1D GetSoilProfile1D(double x) { const double diff = 0.001; if (Geometry.Surfaces.Count == 0) { foreach (var soilLayer2D in Surfaces) { var loop = new GeometryLoop(); var isStartPoint = true; GeometryCurve curve = new GeometryCurve(); foreach (var outerLoopCalcPoint in soilLayer2D.GeometrySurface.OuterLoop.CalcPoints) { Geometry.Points.Add(outerLoopCalcPoint); loop.CalcPoints.Add(outerLoopCalcPoint); Geometry.Surfaces.Add(soilLayer2D.GeometrySurface); if (isStartPoint) { curve.HeadPoint = outerLoopCalcPoint; } else { curve.EndPoint = outerLoopCalcPoint; loop.CurveList.Add(curve); curve = new GeometryCurve(); curve.HeadPoint = outerLoopCalcPoint; } isStartPoint = false; } curve.EndPoint = loop.CurveList.First().HeadPoint; Geometry.Curves.Add(curve); loop.CurveList.Add(curve); Geometry.Loops.Add(loop); var surface = new GeometrySurface(); surface.OuterLoop = loop; Geometry.Surfaces.Add(surface); } Geometry.Right = Geometry.MaxGeometryPointsX; Geometry.Left = Geometry.MinGeometryPointsX; } var soilProfile = new SoilProfile1D { Name = "Generated at x = " + x + " from " + Name }; var detector = new LayerDetector(Surfaces); if (x > Geometry.Right) { x = Geometry.Right - diff; } if (x < Geometry.Left) { x = Geometry.Left + diff; } detector.DetermineMaterials(x); if (detector.LayerList.Count > 0) { soilProfile.BottomLevel = detector.LayerList[detector.LayerList.Count - 1].EndPoint.Z; for (int i = 0; i < detector.LayerList.Count; i++) { var layer = new SoilLayer1D(detector.LayerList[i].Soil, detector.LayerList[i].StartPoint.Z) { IsAquifer = detector.LayerList[i].IsAquifer }; soilProfile.Layers.Add(layer); } } return soilProfile; } /// /// Get the surface from the point /// /// The point which is supposed to be within the soil layer /// Surface public SoilLayer2D GetSoilLayer(Point2D point) { for (int i = 0; i < Surfaces.Count; i++) { SoilLayer2D surface = Surfaces[i]; GeometryLoop surfaceLine = surface.GeometrySurface.OuterLoop; if (surfaceLine.IsPointInLoopArea(point)) { bool found = true; // if point lies in an innerloop it belongs to another area foreach (var innerloop in surface.GeometrySurface.InnerLoops) { if (innerloop.IsPointInLoopArea(point)) { found = false; } } if (found) { return surface; } } } return null; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return Name; } } }