// 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.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; 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 failure mechanism parameters m stab. /// The failure mechanism parameters for macrostability DamEngine object. 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(); /// 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(); 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()); TransferLocation(Location, kernelModel.PreprocessingModel.LastStage.Locations); // TODO TransferPreconsolidationStresses(); // TODO TransferUniformLoads(); // TODO TransferConsolidationValues(); // TODO TransferMultiplicationFactorsCPhiForUplift(); // TODO TransferWaternets(); // TODO TransferSpencerSlipPlanes(); // TODO TransferUpliftVanCalculationGrid(); // TODO TransferSlipPlaneConstraints(); // TODO TransferLevenbergMarquardtOptions(); // TODO return kernelModel; } 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); } } private void TransferSurfaceLine() { } private void TransferLocation(Data.General.Location location, IList locations) { locations.Add(new Location()); } private void TransferPreconsolidationStresses() { } private void TransferUniformLoads() { } private void TransferConsolidationValues() { } private void TransferMultiplicationFactorsCPhiForUplift() { } private void TransferWaternets() { } private void TransferSpencerSlipPlanes() { } private void TransferUpliftVanCalculationGrid() { } private void TransferSlipPlaneConstraints() { } private void TransferLevenbergMarquardtOptions() { } } }