using System.Data; using Deltares.DamEngine.Calculators.Properties; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon { public static class PlLinesToWaternetConverter { /// /// Converts the pl lines to a waternet. /// /// The pl lines. /// The 1D soil profile. /// Length of the penetration. /// Left side of the 2D profile. /// Right side of the 2D profile. /// public static Waternet ConvertPlLineToWaternet(PlLines plLines, SoilProfile1D soilProfile1D, double penetrationLength, double xLeft, double xRight) { ThrowWhenPlLinesIsNull(plLines); ThrowWhenSoilProfile1DIsNull(soilProfile1D); var waternet = new Waternet { IsGenerated = false, }; var plLine1 = plLines.Lines[PlLineType.Pl1]; waternet.PhreaticLine = new PhreaticLine(); foreach (var plLinePoint in plLine1.Points) { waternet.PhreaticLine.Points.Add(plLinePoint); } var plLine = plLines.Lines[PlLineType.Pl2]; var headLine = ConvertPlLineToHeadLine(plLine); if (headLine != null) { waternet.HeadLineList.Add(headLine); if (soilProfile1D.BottomAquiferLayer != null) { var level = soilProfile1D.BottomAquiferLayer.TopLevel + penetrationLength; var waternetLine = ConvertLevelToWaternetLine(level, xLeft, xRight); waternetLine.HeadLine = headLine; waternet.WaternetLineList.Add(waternetLine); } } plLine = plLines.Lines[PlLineType.Pl3]; headLine = ConvertPlLineToHeadLine(plLine); if (headLine != null) { waternet.HeadLineList.Add(headLine); if (soilProfile1D.InBetweenAquiferLayer != null) { var level = soilProfile1D.InBetweenAquiferLayer.TopLevel; var waternetLine = ConvertLevelToWaternetLine(level, xLeft, xRight); waternetLine.HeadLine = headLine; waternet.WaternetLineList.Add(waternetLine); } } plLine = plLines.Lines[PlLineType.Pl4]; headLine = ConvertPlLineToHeadLine(plLine); if (headLine != null) { waternet.HeadLineList.Add(headLine); if (soilProfile1D.BottomAquiferLayer != null) { var level = soilProfile1D.BottomAquiferLayer.TopLevel; var waternetLine = ConvertLevelToWaternetLine(level, xLeft, xRight); waternetLine.HeadLine = headLine; waternet.WaternetLineList.Add(waternetLine); } } return waternet; } internal static HeadLine ConvertPlLineToHeadLine(PlLine plLine) { HeadLine headLine = null; if (plLine != null) { if (plLine.Points.Count > 0) { headLine = new HeadLine(); foreach (var plLinePoint in plLine.Points) { headLine.Points.Add(plLinePoint); } } } return headLine; } internal static WaternetLine ConvertLevelToWaternetLine(double level, double xLeft, double xRight) { WaternetLine waternetLine = new WaternetLine(); waternetLine.Points.Add(new GeometryPoint(xLeft, level)); waternetLine.Points.Add(new GeometryPoint(xRight, level)); return waternetLine; } /// /// Throws when the 1D soil profile is not assigned. /// /// The 1D soil profile. /// public static void ThrowWhenSoilProfile1DIsNull(SoilProfile1D soilProfile1D) { if (soilProfile1D == null) { throw new NoNullAllowedException(Resources.PlLinesToWaternetConverter_NoSoilProfile1dDefined); } } /// /// Throws when the pl lines object is not assigned. /// /// The pl lines. /// public static void ThrowWhenPlLinesIsNull(PlLines plLines) { if (plLines == null) { throw new NoNullAllowedException(Resources.PlLinesToWaternetConverter_NoPlLinesDefined); } } } }