// Copyright (C) Stichting Deltares 2025. 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 System.Linq;
using Deltares.DamEngine.Calculators.KernelWrappers.Common;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.Geometry;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Data.Standard;
using Deltares.MacroStability.Io.XmlInput;
using CharacteristicPoint = Deltares.DamEngine.Data.Geotechnics.CharacteristicPoint;
using CharacteristicPointSet = Deltares.DamEngine.Data.Geotechnics.CharacteristicPointSet;
using CharacteristicPointType = Deltares.DamEngine.Data.Geotechnics.CharacteristicPointType;
using GeometryCurve = Deltares.DamEngine.Data.Geometry.GeometryCurve;
using GeometryLoop = Deltares.DamEngine.Data.Geometry.GeometryLoop;
using GeometrySurface = Deltares.DamEngine.Data.Geometry.GeometrySurface;
using Point2D = Deltares.DamEngine.Data.Geometry.Point2D;
using PreConsolidationStress = Deltares.DamEngine.Data.Geotechnics.PreConsolidationStress;
using SoilLayer2D = Deltares.DamEngine.Data.Geotechnics.SoilLayer2D;
using SoilProfile2D = Deltares.DamEngine.Data.Geotechnics.SoilProfile2D;
using SoilProfileType = Deltares.MacroStability.Io.XmlInput.SoilProfileType;
using SoilType = Deltares.MacroStability.Io.XmlInput.SoilType;
using SurfaceLine2 = Deltares.DamEngine.Data.Geotechnics.SurfaceLine2;
using Waternet = Deltares.DamEngine.Data.Geometry.Waternet;
namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo;
///
/// Class to create macro stability kernel input from dam engine data.
///
public class FillMacroStabilityKernelInputFromEngine
{
/// Gets or sets the UpliftVan calculation grid.
/// The uplift van calculation grid.
public UpliftVanCalculationGrid UpliftVanCalculationGrid { get; set; }
/// Gets or sets the Bishop calculation grid.
/// The bishop calculation grid.
public BishopCalculationGrid BishopCalculationGrid { get; set; }
/// Gets or sets the traffic load.
/// The traffic load.
public TrafficLoad TrafficLoad { get; set; }
///
/// Creates a full input model data object for Macro stability kernel based on DamEngineData.
///
///
///
///
/// FullInputModelType
public FullInputModelType CreateFullInputModel(DamKernelInput damKernelInput, MStabParameters mStabParameters, Waternet damWaterNet)
{
// The objectRegistry is to be used to keep track of all keys of some of the referenced objects
var objectRegistry = new ObjectRegistry();
var fullInputModelType = new FullInputModelType
{
PreprocessingInput = TransferPreprocessingInput(damKernelInput, mStabParameters),
StabilityModel = TransferStabilityModel(damKernelInput, mStabParameters, damWaterNet, objectRegistry),
VersionInfo = TransferVersionInfo()
};
return fullInputModelType;
}
private PreprocessingInputType TransferPreprocessingInput(DamKernelInput damKernelInput, MStabParameters mStabParameters)
{
if (damKernelInput == null)
{
return null;
}
var preprocessingInputType = new PreprocessingInputType
{
PreConstructionStages = new PreConstructionStageType[1]
};
preprocessingInputType.PreConstructionStages[0] = new PreConstructionStageType();
PreConstructionStageType preConstructionLastStage = preprocessingInputType.PreConstructionStages.Last();
preConstructionLastStage.Surfaceline = new SurfaceLineType();
preConstructionLastStage.CreateWaternet = false;
TransferSurfaceLine(damKernelInput.Location.SurfaceLine, preConstructionLastStage.Surfaceline);
preprocessingInputType.SearchAreaConditions = TransferSearchAreaCondition(mStabParameters);
return preprocessingInputType;
}
private SearchAreaConditionsType TransferSearchAreaCondition(MStabParameters mStabParameters)
{
var preprocessingSearchAreaConditions = new SearchAreaConditionsType
{
AutoGeneticAlgorithmOptions = false,
AutoGeneticAlgorithmOptionsSpecified = true,
AutoLevenbergMarquardtOptions = false,
AutoLevenbergMarquardtOptionsSpecified = true,
AutoSearchAreaSpecified = true,
AutoTangentLinesSpecified = true,
AutomaticForbiddenZones = false,
AutomaticForbiddenZonesSpecified = true,
MaxSpacingBetweenBoundariesSpecified = true,
OnlyAbovePleistoceenSpecified = true,
SlipPlanePosition = SearchAreaConditionsTypeSlipPlanePosition.High,
SlipPlanePositionSpecified = true,
TangentLineNumberSpecified = true,
TangentLineZBottomSpecified = true,
TangentLineZTopSpecified = true
};
switch (mStabParameters.Model)
{
case StabilityModelType.Bishop:
TransferBishopSearchAreaSettings(preprocessingSearchAreaConditions);
break;
case StabilityModelType.UpliftVan:
TransferUpliftVanSearchAreaSettings(preprocessingSearchAreaConditions);
break;
default:
throw new NotImplementedException(nameof(mStabParameters.Model));
}
return preprocessingSearchAreaConditions;
}
private void TransferBishopSearchAreaSettings(SearchAreaConditionsType kernelSearchAreaConditions)
{
// In the Macrostability kernel, for Bishop, the automatic tangent lines are set by AutoSearchArea = True.
// Setting AutoTangentLines to true will create the automatic tangent lines of Uplift-Van which is not desired.
kernelSearchAreaConditions.AutoTangentLines = false;
kernelSearchAreaConditions.AutoSearchArea = BishopCalculationGrid.IsSearchAreaAutomatic;
kernelSearchAreaConditions.TangentLineNumber = BishopCalculationGrid.TangentLineCount;
kernelSearchAreaConditions.TangentLineZTop = BishopCalculationGrid.TangentLineZTop;
kernelSearchAreaConditions.TangentLineZBottom = BishopCalculationGrid.TangentLineZBottom;
kernelSearchAreaConditions.MaxSpacingBetweenBoundaries = 10.0;
}
private void TransferUpliftVanSearchAreaSettings(SearchAreaConditionsType kernelSearchAreaConditions)
{
kernelSearchAreaConditions.AutoTangentLines = UpliftVanCalculationGrid.TangentLinesCreationMethod is TangentLinesDefinition.Automatic or TangentLinesDefinition.OnBoundaryLines;
kernelSearchAreaConditions.AutoSearchArea = UpliftVanCalculationGrid.IsGridsAutomatic;
kernelSearchAreaConditions.OnlyAbovePleistoceen = UpliftVanCalculationGrid.TangentLinesCreationMethod == TangentLinesDefinition.Automatic;
kernelSearchAreaConditions.TangentLineNumber = UpliftVanCalculationGrid.TangentLineCount;
kernelSearchAreaConditions.TangentLineZTop = UpliftVanCalculationGrid.TangentLineZTop;
kernelSearchAreaConditions.TangentLineZBottom = UpliftVanCalculationGrid.TangentLineZBottom;
kernelSearchAreaConditions.MaxSpacingBetweenBoundaries = 0.8;
}
private BishopCalculationCircle TransferBishopCalculationGrid()
{
if (BishopCalculationGrid == null)
{
throw new ArgumentNullException(nameof(BishopCalculationGrid));
}
var kernelBishopCalculationCircle = new BishopCalculationCircle
{
Grid = new CalculationGridType
{
GridXNumber = BishopCalculationGrid.GridXCount,
GridXLeft = BishopCalculationGrid.GridXLeft,
GridXRight = BishopCalculationGrid.GridXRight,
GridZNumber = BishopCalculationGrid.GridZCount,
GridZTop = BishopCalculationGrid.GridZTop,
GridZBottom = BishopCalculationGrid.GridZBottom
}
};
if (!BishopCalculationGrid.IsSearchAreaAutomatic)
{
kernelBishopCalculationCircle.TangentLines = new double[BishopCalculationGrid.TangentLineLevels.Count];
kernelBishopCalculationCircle.TangentLines = BishopCalculationGrid.TangentLineLevels.ToArray();
}
return kernelBishopCalculationCircle;
}
private UpliftVanCalculationGridType TransferUpliftVanCalculationGrid()
{
if (UpliftVanCalculationGrid == null)
{
throw new ArgumentNullException(nameof(UpliftVanCalculationGrid));
}
var kernelUpliftVanCalculationGrid = new UpliftVanCalculationGridType
{
LeftGrid = new CalculationGridType
{
GridXNumber = UpliftVanCalculationGrid.LeftGridXCount,
GridXLeft = UpliftVanCalculationGrid.LeftGridXLeft,
GridXRight = UpliftVanCalculationGrid.LeftGridXRight,
GridZNumber = UpliftVanCalculationGrid.LeftGridZCount,
GridZTop = UpliftVanCalculationGrid.LeftGridZTop,
GridZBottom = UpliftVanCalculationGrid.LeftGridZBottom
},
RightGrid = new CalculationGridType
{
GridXNumber = UpliftVanCalculationGrid.RightGridXCount,
GridXLeft = UpliftVanCalculationGrid.RightGridXLeft,
GridXRight = UpliftVanCalculationGrid.RightGridXRight,
GridZNumber = UpliftVanCalculationGrid.RightGridZCount,
GridZTop = UpliftVanCalculationGrid.RightGridZTop,
GridZBottom = UpliftVanCalculationGrid.RightGridZBottom
}
};
if (UpliftVanCalculationGrid.TangentLinesCreationMethod == TangentLinesDefinition.Specified)
{
kernelUpliftVanCalculationGrid.TangentLines = UpliftVanCalculationGrid.TangentLineLevels.ToArray();
}
return kernelUpliftVanCalculationGrid;
}
private void TransferSurfaceLine(SurfaceLine2 damSurfaceLine, SurfaceLineType kernelSurfaceLine)
{
kernelSurfaceLine.CharacteristicPoints = new SurfaceLineTypeCharacteristicPoint[damSurfaceLine.CharacteristicPoints.Count];
var i = 0;
foreach (CharacteristicPoint damCharPoint in damSurfaceLine.CharacteristicPoints)
{
var kernelCharPoint = new SurfaceLineTypeCharacteristicPoint
{
CharacteristicPointType = InputConversionHelper.ConvertToMacroStabilityCharacteristicPointType(damCharPoint.CharacteristicPointType),
GeometryPoint = new Point2DType
{
X = damCharPoint.Point.X,
Z = damCharPoint.Point.Z
}
};
kernelSurfaceLine.CharacteristicPoints[i] = kernelCharPoint;
i++;
}
}
private StabilityInputType TransferStabilityModel(DamKernelInput damKernelInput, MStabParameters mStabParameters,
Waternet damWaterNet, ObjectRegistry registry)
{
if (damKernelInput == null || mStabParameters == null)
{
return null;
}
var kernelStabilityInput = new StabilityInputType
{
ConstructionStages = new ConstructionStageInputType[1],
SlipPlaneConstraints = new SlipPlaneConstraintsType()
};
switch (mStabParameters.Model)
{
case StabilityModelType.Bishop:
kernelStabilityInput.BishopCalculationCircle = TransferBishopCalculationGrid();
break;
case StabilityModelType.UpliftVan:
kernelStabilityInput.UpliftVanCalculationGrid = TransferUpliftVanCalculationGrid();
break;
default:
throw new NotImplementedException(nameof(mStabParameters.Model));
}
TransferSlipPlaneConstraints(damKernelInput.Location, kernelStabilityInput.SlipPlaneConstraints);
TransferStabilityModelProperties(mStabParameters, kernelStabilityInput);
kernelStabilityInput.ConstructionStages[0] = new ConstructionStageInputType();
ConstructionStageInputType lastStage = kernelStabilityInput.ConstructionStages.Last();
kernelStabilityInput.Soils = new SoilType[damKernelInput.Location.SoilList.Soils.Count];
lastStage.FixedSoilStresses = new FixedSoilStressType[damKernelInput.Location.SoilList.Soils.Count];
TransferSoils(damKernelInput.Location.SoilList, kernelStabilityInput.Soils, lastStage.FixedSoilStresses, registry);
lastStage.SoilProfile = new SoilProfileType();
lastStage.PreconsolidationStresses = new PreconsolidationStressType[damKernelInput.SubSoilScenario.SoilProfile2D.PreconsolidationStresses.Count];
lastStage.WaterDefinition = WaterDefinitionType.WaterNet;
TransferSoilProfile(damKernelInput.SubSoilScenario.SoilProfile2D, lastStage.SoilProfile, lastStage.PreconsolidationStresses, registry);
lastStage.UniformLoads = TransferUniformLoads(TrafficLoad, registry);
TransferTrafficLoadDegreeOfConsolidation(TrafficLoad, damKernelInput.SubSoilScenario.SoilProfile2D,
damKernelInput.Location.TrafficLoadDegreeOfConsolidations, lastStage, registry);
lastStage.Waternet = new WaternetType();
TransferWaternet(damWaterNet, lastStage.Waternet, registry);
// Unused options
lastStage.Earthquake = null;
lastStage.ForbiddenLines = null;
lastStage.Geotextiles = null;
lastStage.LineLoads = null;
lastStage.MultiplicationFactorsCPhiForUplift = null;
lastStage.Nails = null;
lastStage.TreesOnSlope = null;
lastStage.WaterMesh = null;
lastStage.YieldStressField = null;
return kernelStabilityInput;
}
private VersionInfoType TransferVersionInfo()
{
var versionInfoType = new VersionInfoType
{
FileVersion = 2,
AssemblyVersion = "2.0.0.0",
AssemblyName = "Deltares.DamEngine"
};
return versionInfoType;
}
private void TransferStabilityModelProperties(MStabParameters mStabParameters, StabilityInputType kernelStabilityInput)
{
kernelStabilityInput.Orientation = InputConversionHelper.ConvertToMacroStabilityGridOrientation(mStabParameters.GridPosition);
kernelStabilityInput.ModelOption = InputConversionHelper.ConvertToMacroStabilityModelOption(mStabParameters.Model);
// For Bishop, only Grid is possible however if Bishop/UpliftVan was selected, then the SearchAlgorithm concerns only Uplift-Van
kernelStabilityInput.SearchAlgorithm = mStabParameters.Model == StabilityModelType.Bishop ? SearchAlgorithmType.Grid : InputConversionHelper.ConvertToMacroStabilitySearchMethod(mStabParameters.SearchMethod);
if (kernelStabilityInput.SearchAlgorithm == SearchAlgorithmType.BeeswarmAndLevenbergMarquardt)
{
CreateDefaultBeeSwarmOptions(kernelStabilityInput);
}
kernelStabilityInput.GeneticAlgorithmOptions = null;
kernelStabilityInput.LevenbergMarquardtOptions = null;
kernelStabilityInput.MaximumSliceWidthSpecified = true;
kernelStabilityInput.MaximumSliceWidth = 1.0;
kernelStabilityInput.MoveGridSpecified = true;
kernelStabilityInput.MoveGrid = true; // Is not in DamEngine but MUST be true as we use the brute force approach.
kernelStabilityInput.MaxAllowedAngleBetweenSlicesSpecified = true;
kernelStabilityInput.MaxAllowedAngleBetweenSlices = 0;
kernelStabilityInput.RequiredForcePointsInSlicesSpecified = true;
kernelStabilityInput.RequiredForcePointsInSlices = 0;
kernelStabilityInput.TraversalGridPointsSpecified = true;
kernelStabilityInput.TraversalGridPoints = 2;
kernelStabilityInput.TraversalRefinementsSpecified = true;
kernelStabilityInput.TraversalRefinements = 0;
kernelStabilityInput.MaxGridMovesSpecified = true;
kernelStabilityInput.MaxGridMoves = 50;
kernelStabilityInput.NumberOfRefinementsGridSpecified = true;
kernelStabilityInput.NumberOfRefinementsGrid = 2;
kernelStabilityInput.NumberOfRefinementsTangentLinesSpecified = true;
kernelStabilityInput.NumberOfRefinementsTangentLines = 2;
}
private static void TransferSlipPlaneConstraints(Location damLocation, SlipPlaneConstraintsType kernelSlipPlaneConstraints)
{
if (damLocation.StabilityOptions == null)
{
return;
}
kernelSlipPlaneConstraints.SlipPlaneMinDepth = damLocation.StabilityOptions.MinimalCircleDepth ?? 0.0;
if ((damLocation.StabilityOptions.StabilityZoneType == StabilityZoneType.ForbiddenZone) &&
damLocation.StabilityOptions.ForbiddenZoneFactor.HasValue)
{
CharacteristicPointSet characteristicPoints = damLocation.SurfaceLine.CharacteristicPoints;
kernelSlipPlaneConstraints.XEntryMin = characteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtRiver).X;
double xDikeTopAtPolder = characteristicPoints.GetPoint2D(CharacteristicPointType.DikeTopAtPolder).X;
double xDikeToeAtPolder = characteristicPoints.GetPoint2D(CharacteristicPointType.DikeToeAtPolder).X;
double factor = damLocation.StabilityOptions.ForbiddenZoneFactor.Value;
kernelSlipPlaneConstraints.XEntryMax = (xDikeToeAtPolder * factor) + ((1 - factor) * xDikeTopAtPolder);
}
}
private void CreateDefaultBeeSwarmOptions(StabilityInputType kernelStabilityInput)
{
kernelStabilityInput.BeeswarmAlgorithmOptions = new BeeSwarmAlgorithmOptionsType
{
EliteCount = 2,
Seed = 1,
CrossOver = 0.3,
Beta = 0.4,
Delta = 0.7,
DifferentialWeight = 0.3,
MaximumNonImprovingGenerations = 10,
PopulationCount = 200,
GenerationCount = 40
};
}
private void TransferSoils(SoilList damSoilList, SoilType[] kernelSoils, FixedSoilStressType[] kernelFixedSoilStresses,
ObjectRegistry registry)
{
if (damSoilList != null)
{
var i = 0;
foreach (Soil damSoil in damSoilList.Soils)
{
SoilType kernelSoil = CreateSoil(damSoil, registry);
kernelSoils[i] = kernelSoil;
var kernelFixedSoilStressType = new FixedSoilStressType
{
POP = damSoil.PoP,
Soil = kernelSoil.Key
};
kernelFixedSoilStresses[i] = kernelFixedSoilStressType;
i++;
}
}
}
private static SoilType CreateSoil(Soil damSoil, ObjectRegistry registry)
{
SoilType kernelSoil = InputConversionHelper.ConvertToMacroStabilitySoil(damSoil);
kernelSoil.Key = registry.GetId(damSoil);
return kernelSoil;
}
private void TransferSoilProfile(SoilProfile2D damSoilProfile2D, SoilProfileType kernelSoilProfile,
PreconsolidationStressType[] kernelPreConsolidationStresses, ObjectRegistry registry)
{
// Add points
kernelSoilProfile.Geometry = new GeometryType
{
Bottom = damSoilProfile2D.Geometry.Bottom,
Left = damSoilProfile2D.Geometry.Left,
Right = damSoilProfile2D.Geometry.Right,
Points = new PointType[damSoilProfile2D.Geometry.Points.Count],
Curves = new CurveType[damSoilProfile2D.Geometry.Curves.Count],
Loops = new LoopType[damSoilProfile2D.Geometry.Loops.Count],
GeometrySurfaces = new GeometrySurfaceType[damSoilProfile2D.Geometry.Surfaces.Count]
};
kernelSoilProfile.SoilSurfaces = new SoilSurfaceType[damSoilProfile2D.Surfaces.Count];
TransferSoilProfileGeometryPoints(damSoilProfile2D, kernelSoilProfile, registry);
TransferSoilProfileGeometryCurves(damSoilProfile2D, kernelSoilProfile, registry);
TransferSoilProfileGeometryLoops(damSoilProfile2D, kernelSoilProfile, registry);
TransferSoilProfileGeometrySurfaces(damSoilProfile2D, kernelSoilProfile, registry);
TransferSoilProfileSoilLayers2D(damSoilProfile2D, kernelSoilProfile, registry);
TransferSoilProfilePreConsolidationStresses(damSoilProfile2D, kernelPreConsolidationStresses);
}
private static void TransferSoilProfilePreConsolidationStresses(SoilProfile2D damSoilProfile2D,
PreconsolidationStressType[] kernelPreConsolidationStresses)
{
var i = 0;
foreach (PreConsolidationStress preConsolidationStress in damSoilProfile2D.PreconsolidationStresses)
{
var kernelPreConsolidationStressType = new PreconsolidationStressType
{
Point = new Point2DType
{
X = preConsolidationStress.X,
Z = preConsolidationStress.Z
},
StressValue = preConsolidationStress.StressValue
};
kernelPreConsolidationStresses[i] = kernelPreConsolidationStressType;
i++;
}
}
private static void TransferSoilProfileSoilLayers2D(SoilProfile2D damSoilProfile2D, SoilProfileType kernelSoilProfile,
ObjectRegistry registry)
{
var i = 0;
foreach (SoilLayer2D damSoilLayer2D in damSoilProfile2D.Surfaces)
{
var kernelSoilLayer2D = new SoilSurfaceType
{
Key = registry.GetId(damSoilLayer2D),
Name = damSoilLayer2D.Name,
IsAquifer = damSoilLayer2D.IsAquifer,
GeometrySurface = registry.GetId(damSoilLayer2D.GeometrySurface),
Soil = registry.GetId(damSoilLayer2D.Soil),
WaterPressureInterpolationModelSpecified = true,
WaterPressureInterpolationModel = InputConversionHelper.ConvertToMacroStabilityWaterPressureInterpolationModel(
damSoilLayer2D.WaterpressureInterpolationModel)
};
kernelSoilProfile.SoilSurfaces[i] = kernelSoilLayer2D;
i++;
}
}
private static void TransferSoilProfileGeometrySurfaces(SoilProfile2D damSoilProfile2D, SoilProfileType kernelSoilProfile,
ObjectRegistry registry)
{
var i = 0;
foreach (SoilLayer2D damSurface in damSoilProfile2D.Surfaces)
{
var kernelGeometrySurface = new GeometrySurfaceType
{
Key = registry.GetId(damSurface)
};
GeometrySurface damGeometrySurface = damSurface.GeometrySurface;
kernelGeometrySurface.OuterLoop = registry.GetId(damGeometrySurface.OuterLoop);
kernelGeometrySurface.InnerLoops = new GeometrySurfaceTypeInnerLoop[damGeometrySurface.InnerLoops.Count];
var j = 0;
foreach (GeometryLoop damSurfaceInnerLoop in damGeometrySurface.InnerLoops)
{
kernelGeometrySurface.InnerLoops[j] = new GeometrySurfaceTypeInnerLoop
{
Loop = registry.GetId(damSurfaceInnerLoop)
};
}
kernelSoilProfile.Geometry.GeometrySurfaces[i] = kernelGeometrySurface;
}
}
private static void TransferSoilProfileGeometryLoops(SoilProfile2D damSoilProfile2D, SoilProfileType kernelSoilProfile,
ObjectRegistry registry)
{
var i = 0;
foreach (GeometryLoop damLoop in damSoilProfile2D.Geometry.Loops)
{
var kernelLoop = new LoopType
{
Key = registry.GetId(damLoop),
Curves = new LoopTypeCurve[damLoop.CurveList.Count]
};
var j = 0;
foreach (GeometryCurve damCurve in damLoop.CurveList)
{
var kernelCurve = new LoopTypeCurve
{
Curve = registry.GetId(damCurve)
};
kernelLoop.Curves[j] = kernelCurve;
j++;
}
kernelSoilProfile.Geometry.Loops[i] = kernelLoop;
i++;
}
}
private static void TransferSoilProfileGeometryCurves(SoilProfile2D damSoilProfile2D, SoilProfileType kernelSoilProfile,
ObjectRegistry registry)
{
var i = 0;
foreach (GeometryCurve damCurve in damSoilProfile2D.Geometry.Curves)
{
var kernelCurve = new CurveType
{
HeadPoint = registry.GetId(damCurve.HeadPoint),
EndPoint = registry.GetId(damCurve.EndPoint),
Key = registry.GetId(damCurve)
};
kernelSoilProfile.Geometry.Curves[i] = kernelCurve;
i++;
}
}
private static void TransferSoilProfileGeometryPoints(SoilProfile2D damSoilProfile2D, SoilProfileType kernelSoilProfile,
ObjectRegistry registry)
{
var i = 0;
foreach (Point2D damPoint in damSoilProfile2D.Geometry.Points)
{
var kernelPoint = new PointType
{
X = damPoint.X,
Z = damPoint.Z,
Key = registry.GetId(damPoint)
};
kernelSoilProfile.Geometry.Points[i] = kernelPoint;
i++;
}
}
private UniformLoadType[] TransferUniformLoads(TrafficLoad damTrafficLoad, ObjectRegistry registry)
{
if (damTrafficLoad != null)
{
var kernelUniformLoads = new UniformLoadType[1];
var kernelUniformLoad = new UniformLoadType
{
XStart = damTrafficLoad.XStart,
XEnd = damTrafficLoad.XEnd,
Pressure = damTrafficLoad.Pressure,
DistributionAngle = 0.0,
Key = registry.GetId(damTrafficLoad)
};
kernelUniformLoads[0] = kernelUniformLoad;
return kernelUniformLoads;
}
return null;
}
private static void TransferTrafficLoadDegreeOfConsolidation(TrafficLoad damTrafficLoad, SoilProfile2D damSoilProfile,
IList damDegreeOfConsolidations,
ConstructionStageInputType kernelStage, ObjectRegistry registry)
{
if (damDegreeOfConsolidations != null && kernelStage.UniformLoads.Length == 1)
{
var i = 0;
kernelStage.ConsolidationValues = new ConsolidationValuesTypeConsolidationValue[damDegreeOfConsolidations.Count];
foreach (SoilLayer2D damSurface in damSoilProfile.Surfaces)
{
kernelStage.ConsolidationValues[i] = new ConsolidationValuesTypeConsolidationValue
{
Consolidator = registry.GetId(damTrafficLoad),
Consolidated = registry.GetId(damSurface),
Value = damDegreeOfConsolidations.Find(t => t.SoilName == damSurface.Soil.Name).DegreeOfConsolidation
};
i++;
}
}
}
private static void TransferWaternet(Waternet damWaternet, WaternetType kernelWaternet, ObjectRegistry registry)
{
kernelWaternet.Name = damWaternet.Name;
kernelWaternet.UnitWeightWater = damWaternet.UnitWeight;
kernelWaternet.UnitWeightWaterSpecified = true;
// Head Lines
kernelWaternet.HeadLines = new HeadLineType[damWaternet.HeadLineList.Count];
var i = 0;
foreach (HeadLine damHeadLine in damWaternet.HeadLineList)
{
HeadLineType kernelHeadLine = CreateHeadLine(damHeadLine, registry);
kernelWaternet.HeadLines[i] = kernelHeadLine;
i++;
}
// Phreatic Line
kernelWaternet.PhreaticLine = CreatePhreaticLine(damWaternet.PhreaticLine, registry);
// Waternet Lines
kernelWaternet.WaternetLines = new WaternetTypeWaternetLine[damWaternet.WaternetLineList.Count];
i = 0;
foreach (WaternetLine damWaternetLine in damWaternet.WaternetLineList)
{
WaternetTypeWaternetLine waternetTypeWaternetLine = CreateWaternetTypeWaternetLine(damWaternetLine, registry);
kernelWaternet.WaternetLines[i] = waternetTypeWaternetLine;
i++;
}
}
private static HeadLineType CreateHeadLine(HeadLine damHeadLine, ObjectRegistry registry)
{
return new HeadLineType
{
Key = registry.GetId(damHeadLine),
WaternetLine = CreateWaternetLineType(damHeadLine)
};
}
private static HeadLineType CreatePhreaticLine(PhreaticLine damPhreaticLine, ObjectRegistry registry)
{
return new HeadLineType
{
Key = registry.GetId(damPhreaticLine),
WaternetLine = CreateWaternetLineType(damPhreaticLine)
};
}
private static WaternetTypeWaternetLine CreateWaternetTypeWaternetLine(WaternetLine damWaternetLine, ObjectRegistry registry)
{
var waternetTypeWaternetLine = new WaternetTypeWaternetLine
{
Name = damWaternetLine.Name,
AssociatedHeadLineSpecified = true,
AssociatedHeadLine = registry.GetId(damWaternetLine.HeadLine),
Points = new Point2DType[damWaternetLine.Points.Count]
};
for (var i = 0; i < damWaternetLine.Points.Count; i++)
{
waternetTypeWaternetLine.Points[i] = CreateWaternetLinePoint(damWaternetLine.Points[i]);
}
return waternetTypeWaternetLine;
}
private static WaternetLineType CreateWaternetLineType(GeometryPointString damWaternetLine)
{
var waternetLineType = new WaternetLineType
{
Name = damWaternetLine.Name,
Points = new Point2DType[damWaternetLine.Points.Count]
};
for (var i = 0; i < damWaternetLine.Points.Count; i++)
{
waternetLineType.Points[i] = CreateWaternetLinePoint(damWaternetLine.Points[i]);
}
return waternetLineType;
}
private static Point2DType CreateWaternetLinePoint(Point2D damPoint)
{
if (damPoint == null)
{
return null;
}
return new Point2DType
{
X = damPoint.X,
Z = damPoint.Z
};
}
}