// 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.MacroStability.Data;
using Deltares.MacroStability.Geometry;
using Deltares.MacroStability.Kernel;
using Deltares.MacroStability.Preprocessing;
using GeometryPoint = Deltares.DamEngine.Data.Geometry.GeometryPoint;
using Location = Deltares.MacroStability.WaternetCreator.Location;
using SoilLayer2D = Deltares.DamEngine.Data.Geotechnics.SoilLayer2D;
namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo
{
public class FillWtiKernelData
{
public Data.General.Location Location { get; set; }
public Data.Geotechnics.SoilProfile2D SoilProfile2D { get; set; }
public Data.Geotechnics.SurfaceLine2 SurfaceLine2 { get; set; }
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 DamProjectData object filled with Wti 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);
TransferVersionInfo(); // TODO
TransferSoils(SoilProfile2D, kernelModel.StabilityModel.SoilModel.Soils);
kernelModel.StabilityModel.SoilProfile = new SoilProfile2D();
TransferSoilProfile(SoilProfile2D, kernelModel.StabilityModel.SoilProfile); // TODO
TransferSurfaceLine(); // TODO
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 TransferSoilProfile(DamEngine.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);
}
}
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 TransferVersionInfo()
{
}
private void TransferSoils(Data.Geotechnics.SoilProfile2D damSoilProfile2D, IList soils)
{
// 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()
{
}
}
}