using System; using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard; using Deltares.Standard.Logging; namespace Deltares.Dam.Data { public class WaterBoardPostProcessRelativeProfilesException : Exception { public WaterBoardPostProcessRelativeProfilesException(string message) : base(message) { } } public static class WaterBoardPostProcessRelativeProfiles { /// /// Creates the absolute profiles based on the original profiles. /// The original profiles are considered to be relative to the specified characteristic point /// 1) Create a copy of the assigned segment for each location /// 2) In the copy the toplevel of the soilprofile will be moved to the z-coordinate of the specified characteristic point /// /// The water board. /// The characteristic point to which the soilprofile toplevel should be moved public static void CreateAbsoluteProfiles(WaterBoard waterBoard, CharacteristicPointType characteristicPointType) { foreach (Dike dike in waterBoard.Dikes) { foreach (Location location in dike.Locations) { var orgSegment = location.Segment; if (orgSegment != null) { var newSegment = new Segment(); newSegment.Name = String.Format("Segment {0}", location.Name); foreach (SoilGeometryProbability orgSoilGeometryProbability in orgSegment.SoilProfileProbabilities) { try { var characteristicGeometryPoint = location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(characteristicPointType); if (characteristicGeometryPoint == null) { throw new WaterBoardPostProcessRelativeProfilesException(String.Format("Characteristic point {0} is not defined", characteristicPointType)); } if (orgSoilGeometryProbability.SoilGeometryType.Equals(SoilGeometryType.SoilGeometry2D)) { throw new WaterBoardPostProcessRelativeProfilesException("Cannnot apply releative profiles for 2d soilprofiles"); } // Create a copy of the original SoilGeometryProbability SoilGeometryProbability newSoilGeometryProbability = new SoilGeometryProbability(); newSoilGeometryProbability.Assign(orgSoilGeometryProbability); // Move all layer boundaries so toplevel of the soilprofile1D will be at level of specified characteristic point // Dependent if deltaZ is positive or negative, the bottomLevel should be adjusted before or after adjusting the layers // This is necessary, because the bottomlevel is adjusted automatically during adjustment of layers var soilProfile1D = newSoilGeometryProbability.SoilProfile; double deltaZ = characteristicGeometryPoint.Z - soilProfile1D.TopLevel; if (deltaZ < 0) { soilProfile1D.BottomLevel += deltaZ; } foreach (SoilLayer1D soilLayer1D in soilProfile1D.Layers) { soilLayer1D.TopLevel += deltaZ; } if (deltaZ > 0) { soilProfile1D.BottomLevel += deltaZ; } // Add new SoilGeometryProbability to new segment and assign new segment to location newSegment.SoilProfileProbabilities.Add(newSoilGeometryProbability); location.Segment = newSegment; waterBoard.Segments.Add(newSegment); } catch (Exception e) { LogManager.Messages.Add(new LogMessage(LogMessageType.Error, location, String.Format("Error in location '{0}' applying relative height for soilprofile '{1}': {2} ", location.Name, orgSoilGeometryProbability.SoilGeometryName, e.Message))); } } } } } } } }