// Copyright (C) Stichting Deltares 2019. 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 Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geotechnics; using Deltares.MacroStability.Data; using Deltares.MacroStability.Geometry; using Deltares.MacroStability.Kernel; using Deltares.MacroStability.Preprocessing; using CharacteristicPoint = Deltares.MacroStability.Geometry.CharacteristicPoint; using Location = Deltares.MacroStability.WaternetCreator.Location; using Soil = Deltares.MacroStability.Geometry.Soil; using SoilLayer2D = Deltares.DamEngine.Data.Geotechnics.SoilLayer2D; using SoilProfile2D = Deltares.MacroStability.Geometry.SoilProfile2D; using SurfaceLine2 = Deltares.MacroStability.Geometry.SurfaceLine2; using Waternet = Deltares.DamEngine.Data.Geometry.Waternet; namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo { /// Fill the kernel data model from DamEngine data objects public class FillWtiKernelData { /// Gets or sets the SoilList DamEngine object /// The soil list. public SoilList SoilList { get; set; } /// Gets or sets the location DamEngine object. /// The location. public Data.General.Location Location { get; set; } /// Gets or sets the SoilProfile2D DamEngine object. /// The soil profile2 d. public Data.Geotechnics.SoilProfile2D SoilProfile2D { get; set; } /// Gets or sets the SurfaceLine2 DamEngine object. /// The surface line2. public Data.Geotechnics.SurfaceLine2 SurfaceLine2 { get; set; } /// Gets or sets the waternet. /// The waternet. public Waternet Waternet { get; set; } /// Gets or sets the UpliftVan calculation grid. /// The uplift van calculation grid. public UpliftVanCalculationGrid UpliftVanCalculationGrid { get; set; } /// Gets or sets the traffic load. /// The traffic load. public TrafficLoad TrafficLoad { get; set; } /// Gets or sets the MStab failure mechanism parameters. /// The MStab failure mechanism parameters. public FailureMechanismParametersMStab FailureMechanismParametersMStab { get; set; } private Dictionary dictSoils = new Dictionary(); private Dictionary dictPoints = new Dictionary(); private Dictionary dictCurves = new Dictionary(); private Dictionary dictLoops = new Dictionary(); private Dictionary dictSurfaces = new Dictionary(); private Dictionary dictHeadLines = new Dictionary(); /// Creates the kernel model from dam project data. /// The KernelModel filled with the Dam Project Data public KernelModel CreateKernelModel() { KernelModel kernelModel = new KernelModel(); kernelModel.StabilityModel = new StabilityModel(); kernelModel.PreprocessingModel = new PreprocessingModel(); FailureMechanismParametersMStab.MStabParameters.Model = MStabModelType.UpliftVanWti; TransferWtiStabilityModel(FailureMechanismParametersMStab, kernelModel.StabilityModel); TransferSoils(SoilList, SoilProfile2D, kernelModel.StabilityModel.SoilModel.Soils); kernelModel.StabilityModel.SoilProfile = new SoilProfile2D(); TransferSoilProfile(SoilProfile2D, kernelModel.StabilityModel.SoilProfile); kernelModel.PreprocessingModel.LastStage.SurfaceLine = new SurfaceLine2(); TransferSurfaceLine(SurfaceLine2, kernelModel.PreprocessingModel.LastStage.SurfaceLine); kernelModel.PreprocessingModel.ConstructionStages.Add(new PreprocessingConstructionStage()); kernelModel.PreprocessingModel.LastStage.Locations.Add(new Location()); TransferWaternet(Waternet, kernelModel.StabilityModel.LastStage.GeotechnicsData.CurrentWaternet); TransferUpliftVanCalculationGrid(UpliftVanCalculationGrid, kernelModel.StabilityModel.SlipPlaneUpliftVan, kernelModel.PreprocessingModel.SearchAreaConditions); TransferUniformLoads(TrafficLoad, kernelModel.StabilityModel.LastStage.UniformLoads); return kernelModel; } private void TransferUniformLoads(TrafficLoad trafficLoad, List uniformLoads) { uniformLoads.Clear(); if (trafficLoad != null) { uniformLoads.Add(new SoilStress.Data.UniformLoad() { XStart = trafficLoad.XStart, XEnd = trafficLoad.XEnd, Pressure = trafficLoad.Pressure, DistributionAngle = 0.0, }); } } private void TransferUpliftVanCalculationGrid(UpliftVanCalculationGrid damUpliftVanCalculationGrid, SlipPlaneUpliftVan kernelSlipPlaneUpliftVan, SearchAreaConditions kernelSearchAreaConditions) { if (damUpliftVanCalculationGrid == null) throw new ArgumentNullException(nameof(damUpliftVanCalculationGrid)); if (kernelSlipPlaneUpliftVan == null) throw new ArgumentNullException(nameof(kernelSlipPlaneUpliftVan)); if (kernelSearchAreaConditions == null) throw new ArgumentNullException(nameof(kernelSearchAreaConditions)); damUpliftVanCalculationGrid.IsAuto = kernelSearchAreaConditions.AutoSearchArea; kernelSlipPlaneUpliftVan.SlipPlaneLeftGrid.GridXNumber = damUpliftVanCalculationGrid.LeftGridXCount; kernelSlipPlaneUpliftVan.SlipPlaneLeftGrid.GridXLeft = damUpliftVanCalculationGrid.LeftGridXLeft; kernelSlipPlaneUpliftVan.SlipPlaneLeftGrid.GridXRight = damUpliftVanCalculationGrid.LeftGridXRight; kernelSlipPlaneUpliftVan.SlipPlaneLeftGrid.GridZNumber = damUpliftVanCalculationGrid.LeftGridZCount; kernelSlipPlaneUpliftVan.SlipPlaneLeftGrid.GridZTop = damUpliftVanCalculationGrid.LeftGridZTop; kernelSlipPlaneUpliftVan.SlipPlaneLeftGrid.GridZBottom = damUpliftVanCalculationGrid.LeftGridZBottom; kernelSlipPlaneUpliftVan.SlipPlaneRightGrid.GridXNumber = damUpliftVanCalculationGrid.RightGridXCount; kernelSlipPlaneUpliftVan.SlipPlaneRightGrid.GridXLeft = damUpliftVanCalculationGrid.RightGridXLeft; kernelSlipPlaneUpliftVan.SlipPlaneRightGrid.GridXRight = damUpliftVanCalculationGrid.RightGridXRight; kernelSlipPlaneUpliftVan.SlipPlaneRightGrid.GridZNumber = damUpliftVanCalculationGrid.RightGridZCount; kernelSlipPlaneUpliftVan.SlipPlaneRightGrid.GridZTop = damUpliftVanCalculationGrid.RightGridZTop; kernelSlipPlaneUpliftVan.SlipPlaneRightGrid.GridZBottom = damUpliftVanCalculationGrid.RightGridZBottom; kernelSearchAreaConditions.AutoTangentLines = damUpliftVanCalculationGrid.TangentLineAutomaticAtBoundaries; kernelSlipPlaneUpliftVan.SlipPlaneTangentLine.TangentLineNumber = damUpliftVanCalculationGrid.TangentLineCount; kernelSlipPlaneUpliftVan.SlipPlaneTangentLine.TangentLineZTop = damUpliftVanCalculationGrid.TangentLineZTop; kernelSlipPlaneUpliftVan.SlipPlaneTangentLine.TangentLineZBottom = damUpliftVanCalculationGrid.TangentLineZBottom; } private void TransferWaternet(Waternet damWaternet, MacroStability.Geometry.Waternet kernelWaternet) { // Properties kernelWaternet.IsGenerated = damWaternet.IsGenerated; kernelWaternet.UnitWeight = damWaternet.UnitWeight; // Phreatic Line kernelWaternet.PhreaticLine = new PhreaticLine() { Name = damWaternet.PhreaticLine.Name }; foreach (var damPoint in damWaternet.PhreaticLine.CalcPoints) { kernelWaternet.PhreaticLine.CalcPoints.Add(new Point2D(damPoint.X, damPoint.Z)); } dictHeadLines.Add(damWaternet.PhreaticLine, kernelWaternet.PhreaticLine); // Head Lines foreach (var damHeadLine in damWaternet.HeadLineList) { var kernelHeadLine = new HeadLine() { Name = damHeadLine.Name }; foreach (var damPoint in damHeadLine.CalcPoints) { kernelHeadLine.CalcPoints.Add(new Point2D(damPoint.X, damPoint.Z)); } kernelWaternet.HeadLineList.Add(kernelHeadLine); dictHeadLines.Add(damHeadLine, kernelHeadLine); } // Waternet Lines foreach (var damWaternetLine in damWaternet.WaternetLineList) { var kernelWaternetLine = new WaternetLine() { Name = damWaternetLine.Name }; foreach (var damPoint in damWaternetLine.CalcPoints) { kernelWaternetLine.CalcPoints.Add(new Point2D(damPoint.X, damPoint.Z)); } kernelWaternetLine.HeadLine = dictHeadLines[damWaternetLine.HeadLine]; kernelWaternet.WaternetLineList.Add(kernelWaternetLine); } } private void TransferSurfaceLine(Data.Geotechnics.SurfaceLine2 damSurfaceLine, SurfaceLine2 kernelSurfaceLine) { foreach (var damCharPoint in damSurfaceLine.CharacteristicPoints) { CharacteristicPoint kernelCharPoint; kernelCharPoint = new CharacteristicPoint() { CharacteristicPointType = ConversionHelper.ConvertToMacroStabilityCharacteristicPointType(damCharPoint.CharacteristicPointType), GeometryPoint = new GeometryPoint() { X = damCharPoint.X, Z = damCharPoint.Z } }; kernelSurfaceLine.CharacteristicPoints.Add(kernelCharPoint); } } private void TransferSoilProfile(Data.Geotechnics.SoilProfile2D damSoilProfile2D, SoilProfile2D soilProfile2D) { // Add points foreach (var damPoint in damSoilProfile2D.Geometry.Points) { Point2D kernelPoint2D; if (dictPoints.ContainsKey(damPoint)) { kernelPoint2D = dictPoints[damPoint]; } else { kernelPoint2D = new Point2D() { X = damPoint.X, Z = damPoint.Z }; dictPoints.Add(damPoint, kernelPoint2D); } soilProfile2D.Geometry.Points.Add(kernelPoint2D); } // Add curves foreach (var damCurve in damSoilProfile2D.Geometry.Curves) { GeometryCurve kernelCurve; if (dictCurves.ContainsKey(damCurve)) { kernelCurve = dictCurves[damCurve]; } else { var damHeadPoint = damCurve.HeadPoint; var damEndPoint = damCurve.EndPoint; var kernelHeadPoint = dictPoints[damHeadPoint]; var kernelEndPoint = dictPoints[damEndPoint]; kernelCurve = new GeometryCurve() {HeadPoint = kernelHeadPoint, EndPoint = kernelEndPoint}; dictCurves.Add(damCurve, kernelCurve); } soilProfile2D.Geometry.Curves.Add(kernelCurve); } // Add loops foreach (var damLoop in damSoilProfile2D.Geometry.Loops) { GeometryLoop kernelLoop; if (dictLoops.ContainsKey(damLoop)) { kernelLoop = dictLoops[damLoop]; } else { kernelLoop = new GeometryLoop(){Name = damLoop.Name}; foreach (var damCurve in damLoop.CurveList) { kernelLoop.CurveList.Add(dictCurves[damCurve]); } dictLoops.Add(damLoop, kernelLoop); } soilProfile2D.Geometry.Loops.Add(kernelLoop); } // Add surfaces foreach (var damSurface in damSoilProfile2D.Geometry.Surfaces) { GeometrySurface kernelSurface; if (dictSurfaces.ContainsKey(damSurface)) { kernelSurface = dictSurfaces[damSurface]; } else { kernelSurface = new GeometrySurface() { Name = damSurface.Name }; kernelSurface.OuterLoop = dictLoops[damSurface.OuterLoop]; foreach (var damInnerLoop in damSurface.InnerLoops) { kernelSurface.InnerLoops.Add(dictLoops[damInnerLoop]); } dictSurfaces.Add(damSurface, kernelSurface); } soilProfile2D.Geometry.Surfaces.Add(kernelSurface); } // Add soil surfaces foreach (var damSoilLayer2D in damSoilProfile2D.Surfaces) { MacroStability.Geometry.SoilLayer2D kernelSoilLayer2D = new MacroStability.Geometry.SoilLayer2D(); kernelSoilLayer2D.GeometrySurface = dictSurfaces[damSoilLayer2D.GeometrySurface]; kernelSoilLayer2D.Soil = dictSoils[damSoilLayer2D.Soil]; kernelSoilLayer2D.IsAquifer = damSoilLayer2D.IsAquifer; kernelSoilLayer2D.WaterpressureInterpolationModel = ConversionHelper.ConvertToMacroStabilityWaterpressureInterpolationModel(damSoilLayer2D.WaterpressureInterpolationModel); soilProfile2D.Surfaces.Add(kernelSoilLayer2D); } soilProfile2D.Geometry.Rebox(); // The boundaries should be set correctly } private void TransferWtiStabilityModel(FailureMechanismParametersMStab failureMechanismParametersMStab, StabilityModel stabilityModel) { stabilityModel.MoveGrid = true; // is not in DamEngine datamodel stabilityModel.MaximumSliceWidth = 1.0; // is not in DamEngine datamodel stabilityModel.SearchAlgorithm = ConversionHelper.ConvertToMacroStabilitySearchMethod( failureMechanismParametersMStab.MStabParameters.SearchMethod); stabilityModel.ModelOption = ConversionHelper.ConvertToModelOptions( failureMechanismParametersMStab.MStabParameters.Model); stabilityModel.GridOrientation = ConversionHelper.ConvertToGridOrientation( failureMechanismParametersMStab.MStabParameters.GridPosition); } private void TransferSoils(SoilList soilList, Data.Geotechnics.SoilProfile2D damSoilProfile2D, IList soils) { // Transfer all soils if (soilList != null) { foreach (var damSoil in soilList.Soils) { var kernelSoil = ConversionHelper.ConvertToMacroStabilitySoil(damSoil); dictSoils.Add(damSoil, kernelSoil); } } // Harvest all soils from damSoilProfile2D foreach (SoilLayer2D surface in damSoilProfile2D.Surfaces) { var soil = surface.Soil; if (!dictSoils.ContainsKey(soil)) { Soil macroStabilitySoil = ConversionHelper.ConvertToMacroStabilitySoil(soil); dictSoils.Add(soil, macroStabilitySoil); } } // Add soils to the kernel soillist foreach (KeyValuePair entry in dictSoils) { soils.Add(entry.Value); } } } }