using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Deltares.DamEngine.Data.Geotechnics { public class SoilProfileHelper { public static SoilProfile1D DetermineForSurfaceLineCorrected1DProfileAtX(SoilProfile1D originalSoilProfile1D, SurfaceLine2 surfaceLine, double xCoordinate, Soil dikeEmbankmentMaterial) { var soilProfile = new SoilProfile1D(); soilProfile.Assign(originalSoilProfile1D); var top = surfaceLine.Geometry.GetZatX(xCoordinate); if (soilProfile.TopLevel < top) { var topLayer = new SoilLayer1D { TopLevel = top, Soil = dikeEmbankmentMaterial, SoilProfile = soilProfile, BottomLevel = soilProfile.TopLevel }; soilProfile.Layers.Insert(0, topLayer); } // Todo #Bka: I believe this code should be here to ensure you do not take soil above surface line into account. // Todo However, it causes a series of errors in the tests which I do not get. Have to look at that together with Tom // else if (soilProfile.TopLevel > top) // { // var bottom = RemoveLayersAboveTop(originalSoilProfile1D.LayerCount, soilProfile, top); // var topLayer = new SoilLayer1D // { // TopLevel = top, // Soil = originalSoilProfile1D.Layers[bottom].Soil, // SoilProfile = soilProfile, // IsAquifer = originalSoilProfile1D.Layers[bottom].IsAquifer, // BottomLevel = originalSoilProfile1D.Layers[bottom].BottomLevel // }; // soilProfile.Layers.Insert(0, topLayer); // } soilProfile.BottomLevel = originalSoilProfile1D.BottomLevel; return soilProfile; } private static int RemoveLayersAboveTop(int layerCount, SoilProfile1D soilProfile, double top) { var index = layerCount; for (int i = layerCount - 1; i >= 0; i--) { if (soilProfile.Layers[i].TopLevel > top) { soilProfile.Layers.RemoveAt(i); if (index == layerCount) { index = i; } } } return index; //soilProfile.Layers[0].TopLevel; } } }