// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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.Collections.ObjectModel; using System.Linq; using Core.Common.Base.Geometry; using Core.Common.Geometry; using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.MacroStabilityInwards.Primitives.MacroStabilityInwardsSoilUnderSurfaceLine; namespace Ringtoets.MacroStabilityInwards.Data.SoilProfile { /// /// Class for constructing soil profiles for which the geometry of the layers lay under a surface line. /// public static class MacroStabilityInwardsSoilProfileUnderSurfaceLineFactory { /// /// Creates a new . /// /// The soil profile containing layers under the . /// The surface line which determines the top of the . /// A new containing geometries from the /// under the . /// Thrown when any parameter is null. /// Thrown when the given type /// is not supported. public static MacroStabilityInwardsSoilProfileUnderSurfaceLine Create(IMacroStabilityInwardsSoilProfile soilProfile, MacroStabilityInwardsSurfaceLine surfaceLine) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } var profile1D = soilProfile as MacroStabilityInwardsSoilProfile1D; if (profile1D != null) { return Create(profile1D, surfaceLine); } var profile2D = soilProfile as MacroStabilityInwardsSoilProfile2D; if (profile2D != null) { return Create(profile2D); } throw new NotSupportedException(); } private static MacroStabilityInwardsSoilProfileUnderSurfaceLine Create(MacroStabilityInwardsSoilProfile1D soilProfile, MacroStabilityInwardsSurfaceLine surfaceLine) { Point2D[] localizedSurfaceLine = surfaceLine.LocalGeometry.ToArray(); double geometryBottom = Math.Min(soilProfile.Bottom, localizedSurfaceLine.Min(p => p.Y)) - 1; IEnumerable surfaceLineGeometry = AdvancedMath2D.CompleteLineToPolygon(localizedSurfaceLine, geometryBottom); IEnumerable layerGeometries = soilProfile.Layers.Select( layer => As2DGeometry( layer, soilProfile, localizedSurfaceLine.First().X, localizedSurfaceLine.Last().X)); return GeometriesToIntersections(layerGeometries, surfaceLineGeometry); } private static MacroStabilityInwardsSoilProfileUnderSurfaceLine Create(MacroStabilityInwardsSoilProfile2D soilProfile) { IEnumerable layersUnderSurfaceLine = soilProfile.Layers.Select( layer => new MacroStabilityInwardsSoilLayerUnderSurfaceLine( RingToPoints(layer.OuterRing), layer.Holes.Select(RingToPoints), ToUnderSurfaceLineProperties(layer.Properties))).ToArray(); IEnumerable preconsolidationStressesUnderSurfaceLine = soilProfile.PreconsolidationStresses.Select(ToPreconsolidationStressUnderSurfaceLine).ToArray(); return new MacroStabilityInwardsSoilProfileUnderSurfaceLine(layersUnderSurfaceLine, preconsolidationStressesUnderSurfaceLine); } private static MacroStabilityInwardsSoilLayerPropertiesUnderSurfaceLine ToUnderSurfaceLineProperties( MacroStabilityInwardsSoilLayerProperties properties) { var props = new MacroStabilityInwardsSoilLayerPropertiesUnderSurfaceLine( new MacroStabilityInwardsSoilLayerPropertiesUnderSurfaceLine.ConstructionProperties { UsePop = properties.UsePop, IsAquifer = properties.IsAquifer, ShearStrengthModel = properties.ShearStrengthModel, MaterialName = properties.MaterialName, AbovePhreaticLevelMean = properties.AbovePhreaticLevel.Mean, AbovePhreaticLevelCoefficientOfVariation = properties.AbovePhreaticLevel.CoefficientOfVariation, BelowPhreaticLevelMean = properties.BelowPhreaticLevel.Mean, BelowPhreaticLevelCoefficientOfVariation = properties.BelowPhreaticLevel.CoefficientOfVariation, CohesionMean = properties.Cohesion.Mean, CohesionCoefficientOfVariation = properties.Cohesion.CoefficientOfVariation, FrictionAngleMean = properties.FrictionAngle.Mean, FrictionAngleCoefficientOfVariation = properties.FrictionAngle.CoefficientOfVariation, StrengthIncreaseExponentMean = properties.StrengthIncreaseExponent.Mean, StrengthIncreaseExponentCoefficientOfVariation = properties.StrengthIncreaseExponent.CoefficientOfVariation, ShearStrengthRatioMean = properties.ShearStrengthRatio.Mean, ShearStrengthRatioCoefficientOfVariation = properties.ShearStrengthRatio.CoefficientOfVariation, PopMean = properties.Pop.Mean, PopCoefficientOfVariation = properties.Pop.CoefficientOfVariation }); SetDesignVariablesOfProperties(props); return props; } private static MacroStabilityInwardsPreconsolidationStressUnderSurfaceLine ToPreconsolidationStressUnderSurfaceLine( MacroStabilityInwardsPreconsolidationStress preconsolidationStress) { var macroStabilityInwardsPreconsolidationStressUnderSurfaceLine = new MacroStabilityInwardsPreconsolidationStressUnderSurfaceLine( new MacroStabilityInwardsPreconsolidationStressUnderSurfaceLine.ConstructionProperties { XCoordinate = preconsolidationStress.XCoordinate, ZCoordinate = preconsolidationStress.ZCoordinate, PreconsolidationStressMean = preconsolidationStress.PreconsolidationStress.Mean, PreconsolidationStressCoefficientOfVariation = preconsolidationStress.PreconsolidationStress.CoefficientOfVariation }); macroStabilityInwardsPreconsolidationStressUnderSurfaceLine.PreconsolidationStressDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPreconsolidationStress(macroStabilityInwardsPreconsolidationStressUnderSurfaceLine) .GetDesignValue(); return macroStabilityInwardsPreconsolidationStressUnderSurfaceLine; } private static void SetDesignVariablesOfProperties(MacroStabilityInwardsSoilLayerPropertiesUnderSurfaceLine props) { props.AbovePhreaticLevelDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetAbovePhreaticLevel(props).GetDesignValue(); props.BelowPhreaticLevelDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetBelowPhreaticLevel(props).GetDesignValue(); props.CohesionDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetCohesion(props).GetDesignValue(); props.FrictionAngleDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetFrictionAngle(props).GetDesignValue(); props.StrengthIncreaseExponentDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetStrengthIncreaseExponent(props).GetDesignValue(); props.ShearStrengthRatioDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetShearStrengthRatio(props).GetDesignValue(); props.PopDesignVariable = MacroStabilityInwardsSemiProbabilisticDesignVariableFactory.GetPop(props).GetDesignValue(); } private static Point2D[] RingToPoints(Ring ring) { return ring.Points.ToArray(); } private static MacroStabilityInwardsSoilProfileUnderSurfaceLine GeometriesToIntersections(IEnumerable layerGeometries, IEnumerable surfaceLineGeometry) { var collection = new Collection(); IEnumerable surfaceLineGeometryArray = surfaceLineGeometry.ToArray(); foreach (TempSoilLayerGeometry layer in layerGeometries) { foreach (Point2D[] soilLayerArea in GetSoilLayerWithSurfaceLineIntersection(surfaceLineGeometryArray, layer.OuterLoop)) { collection.Add(new MacroStabilityInwardsSoilLayerUnderSurfaceLine(soilLayerArea, ToUnderSurfaceLineProperties(layer.Properties))); } } return new MacroStabilityInwardsSoilProfileUnderSurfaceLine(collection, Enumerable.Empty()); } private static TempSoilLayerGeometry As2DGeometry(MacroStabilityInwardsSoilLayer1D layer, MacroStabilityInwardsSoilProfile1D soilProfile, double minX, double maxX) { double top = layer.Top; double bottom = top - soilProfile.GetLayerThickness(layer); return new TempSoilLayerGeometry(new[] { new Point2D(minX, top), new Point2D(maxX, top), new Point2D(maxX, bottom), new Point2D(minX, bottom) }, layer.Properties); } private static IEnumerable GetSoilLayerWithSurfaceLineIntersection(IEnumerable surfaceLineGeometry, IEnumerable soilLayerGeometry) { return AdvancedMath2D.PolygonIntersectionWithPolygon(surfaceLineGeometry, soilLayerGeometry).Where(arr => arr.Length > 2); } private class TempSoilLayerGeometry { public TempSoilLayerGeometry(Point2D[] outerLoop, MacroStabilityInwardsSoilLayerProperties properties) { OuterLoop = outerLoop; Properties = properties; } public Point2D[] OuterLoop { get; } public MacroStabilityInwardsSoilLayerProperties Properties { get; } } } }