// Copyright (C) Stichting Deltares 2024. 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.Data.Design;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.General.Sensors;
using Deltares.DamEngine.Data.General.TimeSeries;
using Deltares.DamEngine.Data.Geometry;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Interface.Properties;
using Deltares.DamEngine.Io.XmlInput;
using Location = Deltares.DamEngine.Data.General.Location;
using Segment = Deltares.DamEngine.Data.General.Segment;
using Sensor = Deltares.DamEngine.Io.XmlInput.Sensor;
using SensorGroup = Deltares.DamEngine.Io.XmlInput.SensorGroup;
using SensorLocation = Deltares.DamEngine.Io.XmlInput.SensorLocation;
using Soil = Deltares.DamEngine.Io.XmlInput.Soil;
using SoilProfile1D = Deltares.DamEngine.Data.Geotechnics.SoilProfile1D;
using SoilProfile2D = Deltares.DamEngine.Data.Geotechnics.SoilProfile2D;
using TimeSerie = Deltares.DamEngine.Io.XmlInput.TimeSerie;
namespace Deltares.DamEngine.Interface;
///
/// Fill Dam Engine data object from Input serializer object
///
public class FillDamFromXmlInput
{
///
/// Creates the dam project data from an Input serializer object
///
/// The input.
///
public static DamProjectData CreateDamProjectData(Input input)
{
ValidateInput(input);
var damProjectData = new DamProjectData
{
Dike = new Dike()
};
Dike dike = damProjectData.Dike;
damProjectData.ProjectPath = input.ProjectPath;
damProjectData.CalculationMap = input.CalculationMap;
if (input.MaxCalculationCoresSpecified)
{
damProjectData.MaxCalculationCores = input.MaxCalculationCores;
}
TransferAnalysisSpecification(input, damProjectData);
TransferStabilityParameters(input, damProjectData);
TransferSurfaceLines(input.SurfaceLines, dike.SurfaceLines2);
dike.SoilList = new SoilList();
TransferSoils(input.Soils, dike.SoilList.Soils);
TransferSoilProfiles1D(input.SoilProfiles1D, dike.SoilProfiles, dike.SoilList);
TransferSoilProfiles2D(input.SoilProfiles2D, dike.SoilProfiles2D, dike.SoilList);
TransferTrafficLoadDegreeOfConsolidation(input.TrafficLoadDegreeOfConsolidations, dike);
TransferSegments(input.Segments, damProjectData.Segments);
TransferLocations(input.Locations, dike.Locations, dike.SurfaceLines2, damProjectData.Segments);
if (input.OperationalInputTimeSeries != null)
{
dike.InputTimeSerieCollection = new TimeSerieCollection();
TransferInputTimeSeries(input.OperationalInputTimeSeries, dike.InputTimeSerieCollection);
}
if (input.SensorData != null)
{
damProjectData.SensorData = new SensorData();
TransferSensorData(input.SensorData, damProjectData.SensorData, damProjectData.Dike.Locations);
}
PostProcess(damProjectData);
return damProjectData;
}
///
/// Finds the SoilProfile1D by name.
///
/// The soil profiles.
/// The name.
///
public static SoilProfile1D FindSoilProfile1DByName(IList soilProfiles, string name)
{
foreach (SoilProfile1D soilProfile1D in soilProfiles)
{
if (soilProfile1D.Name == name)
{
return soilProfile1D;
}
}
return null;
}
///
/// Finds the SoilProfile2D by name.
///
/// The soil profiles.
/// The name.
///
public static SoilProfile2D FindSoilProfile2DByName(IList soilProfiles, string name)
{
foreach (SoilProfile2D soilProfile2D in soilProfiles)
{
if (soilProfile2D.Name == name)
{
return soilProfile2D;
}
}
return null;
}
private static void TransferSensorData(InputSensorData inputSensorData, SensorData sensorData, IList locations)
{
// Transfer sensors
foreach (Sensor inputSensor in inputSensorData.Sensors)
{
var plLineMappings = new PlLineType[inputSensor.PlLineMapping.Length];
var plLineMappingIndex = 0;
foreach (SensorPlLineMapping plLineMapping in inputSensor.PlLineMapping)
{
plLineMappings[plLineMappingIndex] = ConversionHelper.ConvertToPlLineType(plLineMapping.PLineType);
plLineMappingIndex++;
}
sensorData.Sensors.Add(new Data.General.Sensors.Sensor
{
ID = inputSensor.Id,
Name = inputSensor.Name,
RelativeLocation = inputSensor.RelativeLocation,
SensorType = ConversionHelper.ConvertToSensorType(inputSensor.SensorType),
PlLineMappings = plLineMappings
});
}
// Transfer sensorgroups
foreach (SensorGroup inputSensorGroup in inputSensorData.SensorGroups)
{
var sensorGroup = new Data.General.Sensors.SensorGroup();
sensorGroup.ID = inputSensorGroup.Id;
foreach (SensorGroupSensorIds sensorId in inputSensorGroup.SensorIds)
{
Data.General.Sensors.Sensor sensor = sensorData.Sensors.First(s => s.ID.Equals(sensorId.SensorId));
sensorGroup.Add(sensor);
}
sensorData.SensorGroups.Add(sensorGroup);
}
// Transfer sensorlocations
foreach (SensorLocation inputSensorLocation in inputSensorData.SensorLocations)
{
var sensorLocation = new Data.General.Sensors.SensorLocation();
sensorLocation.Location = locations.First(l => l.Name.Equals(inputSensorLocation.LocationId));
sensorLocation.Location.SensorLocation = sensorLocation;
sensorLocation.SensorGroup = sensorData.SensorGroups.First(sg => sg.ID.Equals(inputSensorLocation.GroupId));
sensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder);
sensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder);
sensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver);
sensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside);
sensorLocation.SourceTypePl1WaterLevelAtPolder = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl1WaterLevelAtPolder);
sensorLocation.SourceTypePl1WaterLevelAtRiver = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl1WaterLevelAtRiver);
sensorLocation.SourceTypePl3 = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl3);
sensorLocation.SourceTypePl4 = ConversionHelper.ConvertToDataSourceTypeSensors(inputSensorLocation.SourceTypePl4);
sensorData.SensorLocations.Add(sensorLocation);
}
}
private static void TransferInputTimeSeries(TimeSerie[] inputOperationalInputTimeSeries, TimeSerieCollection timeSerieCollection)
{
foreach (TimeSerie inputTimeSerie in inputOperationalInputTimeSeries)
{
Data.General.TimeSeries.TimeSerie timeSerie = timeSerieCollection.AddNewSeries(inputTimeSerie.LocationId);
timeSerie.ParameterId = inputTimeSerie.ParameterId;
timeSerie.ForecastDateTime = inputTimeSerie.ForecastDateTime;
timeSerie.StartDateTime = inputTimeSerie.StartDateTime;
timeSerie.EndDateTime = inputTimeSerie.EndDateTime;
timeSerie.MissVal = inputTimeSerie.MissVal;
timeSerie.Units = inputTimeSerie.Units;
if (inputTimeSerie.Entries.TimeSerieEntry != null)
{
for (var i = 0; i < inputTimeSerie.Entries.TimeSerieEntry.Length; i++)
{
TimeSerieEntriesTimeSerieEntry entry = inputTimeSerie.Entries.TimeSerieEntry[i];
var timeSerieEntry = new TimeSerieEntry
{
DateTime = entry.DateTime,
Value = entry.Value
};
timeSerie.Entries.Add(timeSerieEntry);
}
}
}
}
private static void TransferAnalysisSpecification(Input input, DamProjectData damProjectData)
{
damProjectData.DamProjectType = ConversionHelper.ConvertToDamProjectType(input.DamProjectType);
var calculationSpecification = new DamFailureMechanismeCalculationSpecification();
calculationSpecification.FailureMechanismSystemType = ConversionHelper.ConvertToFailureMechanismSystemType(input.FailureMechanismSystemType);
if (input.AnalysisTypeSpecified)
{
DamProjectCalculationSpecification.SelectedAnalysisType = ConversionHelper.ConvertToAnalysisType(input.AnalysisType);
}
if (input.PipingModelTypeSpecified)
{
calculationSpecification.PipingModelType = ConversionHelper.ConvertToPipingModelType(input.PipingModelType);
}
if (input.StabilityModelTypeSpecified)
{
calculationSpecification.StabilityModelType = ConversionHelper.ConvertToStabilityModelType(input.StabilityModelType);
}
damProjectData.DamProjectCalculationSpecification.DamCalculationSpecifications.Add(calculationSpecification);
}
private static void TransferStabilityParameters(Input input, DamProjectData damProjectData)
{
if (input.StabilityParameters != null)
{
if (damProjectData.DamProjectCalculationSpecification != null)
{
DamFailureMechanismeCalculationSpecification curSpec = damProjectData.DamProjectCalculationSpecification.CurrentSpecification;
if (curSpec != null)
{
curSpec.FailureMechanismParametersMStab = new FailureMechanismParametersMStab();
curSpec.FailureMechanismParametersMStab.MStabParameters = new MStabParameters();
MStabParameters curStabParamas = curSpec.FailureMechanismParametersMStab.MStabParameters;
curStabParamas.SearchMethod = ConversionHelper.ConvertToSearchMethod(input.StabilityParameters.SearchMethod);
// ToDo zant2bka: Is this a good place to set the model? Is was also read in TransferAnalysisSpecification
if (input.StabilityModelTypeSpecified)
{
curStabParamas.Model = ConversionHelper.ConvertToStabilityModelType(input.StabilityModelType);
}
curStabParamas.SlipCircleDefinition = new SlipCircleDefinition();
SlipCircleDefinition slipCircleDefinition = curStabParamas.SlipCircleDefinition;
slipCircleDefinition.UpliftVanGridSizeDetermination = ConversionHelper.ConvertToUpliftVanGridDetermination(input.StabilityParameters.UpliftVanGridDetermination);
slipCircleDefinition.UpliftVanTangentLinesDefinition = ConversionHelper.ConvertToTangentLinesDefinition(input.StabilityParameters.UpliftVanTangentLinesDefinition);
slipCircleDefinition.BishopSearchAreaDetermination = ConversionHelper.ConvertToBishopSearchAreaDetermination(input.StabilityParameters.BishopSearchAreaDetermination);
if (input.StabilityParameters.BishopTangentLinesDistanceSpecified)
{
slipCircleDefinition.BishopTangentLinesDistance = input.StabilityParameters.BishopTangentLinesDistance;
}
if (input.StabilityParameters.BishopGridVerticalPointsCountSpecified)
{
slipCircleDefinition.BishopGridVerticalPointCount = input.StabilityParameters.BishopGridVerticalPointsCount;
}
if (input.StabilityParameters.BishopGridVerticalPointsDistanceSpecified)
{
slipCircleDefinition.BishopGridVerticalPointDistance = input.StabilityParameters.BishopGridVerticalPointsDistance;
}
if (input.StabilityParameters.BishopGridHorizontalPointsCountSpecified)
{
slipCircleDefinition.BishopGridHorizontalPointCount = input.StabilityParameters.BishopGridHorizontalPointsCount;
}
if (input.StabilityParameters.BishopGridHorizontalPointsDistanceSpecified)
{
slipCircleDefinition.BishopGridHorizontalPointDistance = input.StabilityParameters.BishopGridHorizontalPointsDistance;
}
if (input.StabilityParameters.UpliftVanTangentLinesDefinitionSpecified)
{
slipCircleDefinition.UpliftVanTangentLinesDefinition = ConversionHelper.ConvertToTangentLinesDefinition(input.StabilityParameters.UpliftVanTangentLinesDefinition);
}
if (input.StabilityParameters.UpliftVanTangentLinesDistanceSpecified)
{
slipCircleDefinition.UpliftVanTangentLinesDistance = input.StabilityParameters.UpliftVanTangentLinesDistance;
}
if (input.StabilityParameters.UpliftVanGridLeftVerticalPointsCountSpecified)
{
slipCircleDefinition.UpliftVanLeftGridVerticalPointCount = input.StabilityParameters.UpliftVanGridLeftVerticalPointsCount;
}
if (input.StabilityParameters.UpliftVanGridLeftVerticalPointsDistanceSpecified)
{
slipCircleDefinition.UpliftVanLeftGridVerticalPointDistance = input.StabilityParameters.UpliftVanGridLeftVerticalPointsDistance;
}
if (input.StabilityParameters.UpliftVanGridLeftHorizontalPointsCountSpecified)
{
slipCircleDefinition.UpliftVanLeftGridHorizontalPointCount = input.StabilityParameters.UpliftVanGridLeftHorizontalPointsCount;
}
if (input.StabilityParameters.UpliftVanGridLeftHorizontalPointsDistanceSpecified)
{
slipCircleDefinition.UpliftVanLeftGridHorizontalPointDistance = input.StabilityParameters.UpliftVanGridLeftHorizontalPointsDistance;
}
if (input.StabilityParameters.UpliftVanGridRightVerticalPointsCountSpecified)
{
slipCircleDefinition.UpliftVanRightGridVerticalPointCount = input.StabilityParameters.UpliftVanGridRightVerticalPointsCount;
}
if (input.StabilityParameters.UpliftVanGridRightVerticalPointsDistanceSpecified)
{
slipCircleDefinition.UpliftVanRightGridVerticalPointDistance = input.StabilityParameters.UpliftVanGridRightVerticalPointsDistance;
}
if (input.StabilityParameters.UpliftVanGridRightHorizontalPointsCountSpecified)
{
slipCircleDefinition.UpliftVanRightGridHorizontalPointCount = input.StabilityParameters.UpliftVanGridRightHorizontalPointsCount;
}
if (input.StabilityParameters.UpliftVanGridRightHorizontalPointsDistanceSpecified)
{
slipCircleDefinition.UpliftVanRightGridHorizontalPointDistance = input.StabilityParameters.UpliftVanGridRightHorizontalPointsDistance;
}
}
}
}
}
private static void ValidateInput(Input input)
{
if (input == null)
{
throw new ArgumentNullException(Resources.NoInputDefined);
}
if (input.Locations == null)
{
throw new ArgumentNullException(Resources.NoLocationsDefined);
}
foreach (Io.XmlInput.Location location in input.Locations)
{
if (location.DesignScenarios == null)
{
throw new ArgumentNullException(Resources.NoDesignScenariosInLocation);
}
}
if (input.SurfaceLines == null)
{
throw new ArgumentNullException(Resources.NoSurfaceLinesDefined);
}
foreach (SurfaceLine surfaceLine in input.SurfaceLines)
{
if ((surfaceLine.Points == null) || (surfaceLine.Points.Length < 1))
{
throw new ArgumentNullException(string.Format(Resources.NoPointsInSurfaceLine, surfaceLine.Name));
}
}
if (input.Soils == null)
{
throw new ArgumentNullException(Resources.NoSoilsDefined);
}
if (input.Segments == null)
{
throw new ArgumentNullException(Resources.NoSegmentsDefined);
}
}
///
/// Postprocess: connect all objects
///
/// The project.
private static void PostProcess(DamProjectData project)
{
// find proper profiles for segments
foreach (Segment segment in project.Segments)
{
foreach (SoilGeometryProbability segmentSoilProfileProbability in segment.SoilProfileProbabilities)
{
if (segmentSoilProfileProbability.SoilProfileType == SoilProfileType.ProfileType1D)
{
segmentSoilProfileProbability.SoilProfile1D = FindSoilProfile1DByName(project.Dike.SoilProfiles,
segmentSoilProfileProbability.SoilProfile1DName);
}
else
{
segmentSoilProfileProbability.SoilProfile2D = FindSoilProfile2DByName(project.Dike.SoilProfiles2D,
segmentSoilProfileProbability.SoilProfile2DName);
}
}
}
// Set location name for scenarios
foreach (Location location in project.Dike.Locations)
{
foreach (DesignScenario designScenario in location.Scenarios)
{
designScenario.LocationName = location.Name;
}
if (location.CurrentScenario == null && location.Scenarios.Any())
{
location.CurrentScenario = location.Scenarios[0];
}
location.SoilList = project.Dike.SoilList;
location.TrafficLoadDegreeOfConsolidations = project.Dike.TrafficLoadDegreeOfConsolidations;
}
}
private static void TransferSoils(Soil[] inputSoils, List soils)
{
for (var i = 0; i < inputSoils.Length; i++)
{
var soil = new Data.Geotechnics.Soil();
Soil inputSoil = inputSoils[i];
soil.Name = inputSoil.Name;
soil.AbovePhreaticLevel = inputSoil.AbovePhreaticLevelSpecified ? inputSoil.AbovePhreaticLevel : double.NaN;
soil.BelowPhreaticLevel = inputSoil.BelowPhreaticLevelSpecified ? inputSoil.BelowPhreaticLevel : double.NaN;
soil.DiameterD70 = inputSoil.DiameterD70Specified ? inputSoil.DiameterD70 : double.NaN;
soil.PermeabKx = inputSoil.PermeabKxSpecified ? inputSoil.PermeabKx : double.NaN;
soil.ShearStrengthModel = inputSoil.ShearStrengthModelSpecified ? ConversionHelper.ConvertToShearStrengthModel(inputSoil.ShearStrengthModel) : null;
soil.Cohesion = inputSoil.CohesionSpecified ? inputSoil.Cohesion : double.NaN;
soil.FrictionAngle = inputSoil.FrictionAngleSpecified ? inputSoil.FrictionAngle : double.NaN;
soil.Ocr = inputSoil.OcrSpecified ? inputSoil.Ocr : double.NaN;
soil.StrengthIncreaseExponent = inputSoil.StrengthIncreaseExponentSpecified ? inputSoil.StrengthIncreaseExponent : double.NaN;
soil.RatioCuPc = inputSoil.RatioCuPcSpecified ? inputSoil.RatioCuPc : double.NaN;
soil.PoP = inputSoil.PopSpecified ? inputSoil.Pop : double.NaN;
if (inputSoil.SigmaTauCurve != null)
{
soil.SigmaTauCurve = new SigmaTauCurve();
for (var j = 0; j < inputSoil.SigmaTauCurve.Length; j++)
{
SigmaTauCurveSigmaTauPoint point = inputSoil.SigmaTauCurve[j];
soil.SigmaTauCurve.Points.Add(new SigmaTauPoint(point.Sigma, point.Tau));
}
}
if (inputSoil.SuTable != null)
{
soil.SuTableCurve = new SuTableCurve();
for (var j = 0; j < inputSoil.SuTable.Length; j++)
{
SuTableSigmaSuPoint point = inputSoil.SuTable[j];
soil.SuTableCurve.Points.Add(new SigmaSuPoint(point.Sigma, point.Su));
}
}
soils.Add(soil);
}
}
private static void TransferSurfaceLines(SurfaceLine[] inputSurfaceLines, IList dikeSurfaceLines)
{
for (var i = 0; i < inputSurfaceLines.Length; i++)
{
var surfaceLine = new SurfaceLine2();
SurfaceLine inputSurfaceLine = inputSurfaceLines[i];
surfaceLine.Name = inputSurfaceLine.Name;
surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry;
AddPointsToSurfaceLine(inputSurfaceLine, surfaceLine);
dikeSurfaceLines.Add(surfaceLine);
}
}
private static void AddPointsToSurfaceLine(SurfaceLine inputSurfaceLine, SurfaceLine2 surfaceLine)
{
surfaceLine.Geometry = new GeometryPointString();
for (var j = 0; j < inputSurfaceLine.Points.Length; j++)
{
SurfaceLinePoint inputPoint = inputSurfaceLine.Points[j];
var geometryPoint = new Point2D()
{
X = inputPoint.X,
Z = inputPoint.Z
};
surfaceLine.AddCharacteristicPoint(geometryPoint, ConversionHelper.ConvertToDamPointType(inputPoint.PointType));
}
}
private static void TransferLocations(Io.XmlInput.Location[] inputLocations,
IList dikeLocations, IList dikeSurfaceLines, IList segments)
{
for (var i = 0; i < inputLocations.Length; i++)
{
var location = new Location();
Io.XmlInput.Location inputLocation = inputLocations[i];
location.Name = inputLocation.Name;
if (inputLocation.DistanceToEntryPointSpecified)
{
location.DistanceToEntryPoint = inputLocation.DistanceToEntryPoint;
}
// Waternet options
LocationWaternetOptions waternetOptions = inputLocation.WaternetOptions;
location.ModelParametersForPlLines.PlLineCreationMethod = ConversionHelper.ConvertToPhreaticLineCreationMethod(waternetOptions.PhreaticLineCreationMethod);
location.IntrusionVerticalWaterPressure = ConversionHelper.ConvertToIntrusionVerticalWaterPressure(waternetOptions.IntrusionVerticalWaterPressure);
location.ModelParametersForPlLines.DampingFactorPl3 = waternetOptions.DampingFactorPl3;
location.ModelParametersForPlLines.DampingFactorPl4 = waternetOptions.DampingFactorPl4;
location.ModelParametersForPlLines.PenetrationLength = waternetOptions.PenetrationLength;
location.SlopeDampingPiezometricHeightPolderSide = waternetOptions.SlopeDampingFactor;
// Design options
LocationDesignOptions designOptions = inputLocation.DesignOptions;
if (designOptions != null)
{
location.RedesignDikeHeight = designOptions.RedesignDikeHeight;
location.RedesignDikeShoulder = designOptions.RedesignDikeShoulder;
location.ShoulderEmbankmentMaterial = designOptions.ShoulderEmbankmentMaterial;
location.StabilityShoulderGrowSlope = designOptions.StabilityShoulderGrowSlope;
location.StabilityShoulderGrowDeltaX = designOptions.StabilityShoulderGrowDeltaX;
location.StabilitySlopeAdaptionDeltaX = designOptions.StabilitySlopeAdaptionDeltaX;
location.SlopeAdaptionStartCotangent = designOptions.SlopeAdaptionStartCotangent;
location.SlopeAdaptionEndCotangent = designOptions.SlopeAdaptionEndCotangent;
location.SlopeAdaptionStepCotangent = designOptions.SlopeAdaptionStepCotangent;
location.UseNewDikeTopWidth = designOptions.NewDikeTopWidthSpecified;
if (designOptions.NewDikeTopWidthSpecified)
{
location.NewDikeTopWidth = designOptions.NewDikeTopWidth;
}
location.UseNewDikeSlopeInside = designOptions.NewDikeSlopeInsideSpecified;
if (designOptions.NewDikeSlopeInsideSpecified)
{
location.NewDikeSlopeInside = designOptions.NewDikeSlopeInside;
}
location.UseNewDikeSlopeOutside = designOptions.NewDikeSlopeOutsideSpecified;
if (designOptions.NewDikeSlopeOutsideSpecified)
{
location.NewDikeSlopeOutside = designOptions.NewDikeSlopeOutside;
}
location.UseNewShoulderTopSlope = designOptions.NewShoulderTopSlopeSpecified;
if (designOptions.NewShoulderTopSlopeSpecified)
{
location.NewShoulderTopSlope = designOptions.NewShoulderTopSlope;
}
location.UseNewShoulderBaseSlope = designOptions.NewShoulderBaseSlopeSpecified;
if (designOptions.NewShoulderBaseSlopeSpecified)
{
location.NewShoulderBaseSlope = designOptions.NewShoulderBaseSlope;
}
location.UseNewMaxHeightShoulderAsFraction = designOptions.NewMaxHeightShoulderAsFractionSpecified;
if (designOptions.NewMaxHeightShoulderAsFractionSpecified)
{
location.NewMaxHeightShoulderAsFraction = designOptions.NewMaxHeightShoulderAsFraction;
}
location.UseNewMinDistanceDikeToeStartDitch = designOptions.NewMinDistanceDikeToeStartDitchSpecified;
if (designOptions.NewMinDistanceDikeToeStartDitchSpecified)
{
location.NewMinDistanceDikeToeStartDitch = designOptions.NewMinDistanceDikeToeStartDitch;
}
location.UseNewDitchDefinition = designOptions.UseNewDitchDefinition;
if (designOptions.NewWidthDitchBottomSpecified)
{
location.NewWidthDitchBottom = designOptions.NewWidthDitchBottom;
}
if (designOptions.NewSlopeAngleDitchSpecified)
{
location.NewSlopeAngleDitch = designOptions.NewSlopeAngleDitch;
}
if (designOptions.NewDepthDitchSpecified)
{
location.NewDepthDitch = designOptions.NewDepthDitch;
}
location.StabilityDesignMethod = ConversionHelper.ConvertToDamStabilityDesignMethod(designOptions.StabilityDesignMethod);
}
SurfaceLine2 surfaceLine = dikeSurfaceLines.First(n => n.Name.Equals(inputLocation.SurfaceLineName));
location.SurfaceLine = surfaceLine;
Segment segment = null;
if (segments.Count > 0)
{
segment = segments.First(s => s.Name.Equals(inputLocation.SegmentName));
}
location.Segment = segment;
if (inputLocation.DesignScenarios != null)
{
for (var j = 0; j < inputLocation.DesignScenarios.Length; j++)
{
var designScenario = new DesignScenario();
LocationDesignScenario inputLocationDesignScenario = inputLocation.DesignScenarios[j];
designScenario.LocationScenarioID = inputLocationDesignScenario.Id;
designScenario.PolderLevel = inputLocationDesignScenario.PolderLevel;
designScenario.RiverLevel = inputLocationDesignScenario.RiverLevel;
designScenario.RiverLevelLow = (inputLocationDesignScenario.RiverLevelLowSpecified ? inputLocationDesignScenario.RiverLevelLow : null);
designScenario.DikeTableHeight = (inputLocationDesignScenario.DikeTableHeightSpecified ? inputLocationDesignScenario.DikeTableHeight : null);
designScenario.PlLineOffsetBelowDikeTopAtRiver = inputLocationDesignScenario.PlLineOffsetBelowDikeTopAtRiver;
designScenario.PlLineOffsetBelowDikeTopAtPolder = inputLocationDesignScenario.PlLineOffsetBelowDikeTopAtPolder;
designScenario.PlLineOffsetBelowShoulderBaseInside = inputLocationDesignScenario.PlLineOffsetBelowShoulderBaseInside;
designScenario.PlLineOffsetBelowDikeToeAtPolder = inputLocationDesignScenario.PlLineOffsetBelowDikeToeAtPolder;
designScenario.UsePlLineOffsetBelowDikeCrestMiddle = inputLocationDesignScenario.PlLineOffsetBelowDikeCrestMiddleSpecified;
designScenario.PlLineOffsetBelowDikeCrestMiddle = inputLocationDesignScenario.PlLineOffsetBelowDikeCrestMiddle;
designScenario.UsePlLineOffsetFactorBelowShoulderCrest = inputLocationDesignScenario.PlLineOffsetFactorBelowShoulderCrestSpecified;
designScenario.PlLineOffsetFactorBelowShoulderCrest = inputLocationDesignScenario.PlLineOffsetFactorBelowShoulderCrest;
designScenario.HeadPl2 = (inputLocationDesignScenario.HeadPl2Specified ? inputLocationDesignScenario.HeadPl2 : null);
designScenario.HeadPl3 = (inputLocationDesignScenario.HeadPl3Specified ? inputLocationDesignScenario.HeadPl3 : null);
designScenario.HeadPl4 = (inputLocationDesignScenario.HeadPl4Specified ? inputLocationDesignScenario.HeadPl4 : null);
designScenario.UpliftCriterionStability = inputLocationDesignScenario.UpliftCriterionStability;
designScenario.UpliftCriterionPiping = inputLocationDesignScenario.UpliftCriterionPiping;
designScenario.RequiredSafetyFactorStabilityInnerSlope = inputLocationDesignScenario.RequiredSafetyFactorStabilityInnerSlope;
designScenario.RequiredSafetyFactorStabilityOuterSlope = inputLocationDesignScenario.RequiredSafetyFactorStabilityOuterSlope;
designScenario.RequiredSafetyFactorPiping = inputLocationDesignScenario.RequiredSafetyFactorPiping;
location.Scenarios.Add(designScenario);
}
location.CurrentScenario = location.Scenarios[0];
}
location.DikeEmbankmentMaterial = inputLocation.DikeEmbankmentMaterial;
if (inputLocation.StabilityOptions != null)
{
location.StabilityOptions = new StabilityOptions
{
StabilityZoneType = ConversionHelper.ConvertToZoneType(inputLocation.StabilityOptions.ZoneType)
};
if (inputLocation.StabilityOptions.ForbiddenZoneFactorSpecified)
{
location.StabilityOptions.ForbiddenZoneFactor = inputLocation.StabilityOptions.ForbiddenZoneFactor;
}
if (inputLocation.StabilityOptions.TrafficLoadSpecified)
{
location.StabilityOptions.TrafficLoad = inputLocation.StabilityOptions.TrafficLoad;
}
if (inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidationSpecified)
{
location.StabilityOptions.TrafficLoadDegreeOfConsolidation = inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidation;
}
if (inputLocation.StabilityOptions.MinimumCircleDepthSpecified)
{
location.StabilityOptions.MinimalCircleDepth = inputLocation.StabilityOptions.MinimumCircleDepth;
}
}
dikeLocations.Add(location);
}
}
private static void TransferSoilProfiles1D(Io.XmlInput.SoilProfile1D[] inputSoilProfiles1D,
IList dikeSoilProfiles, SoilList soils)
{
if (inputSoilProfiles1D != null)
{
for (var i = 0; i < inputSoilProfiles1D.Length; i++)
{
var soilProfile1D = new SoilProfile1D();
Io.XmlInput.SoilProfile1D inputSoilProfile1D = inputSoilProfiles1D[i];
soilProfile1D.Name = inputSoilProfile1D.Name;
soilProfile1D.BottomLevel = inputSoilProfile1D.BottomLevel;
AddLayers1D(inputSoilProfile1D, soilProfile1D, soils);
dikeSoilProfiles.Add(soilProfile1D);
}
}
}
private static void TransferTrafficLoadDegreeOfConsolidation(InputTrafficLoadDegreeOfConsolidation[] inputDegreeOfConsolidations,
Dike dike)
{
if (inputDegreeOfConsolidations != null)
{
dike.TrafficLoadDegreeOfConsolidations = new List();
foreach (InputTrafficLoadDegreeOfConsolidation degreeOfConsolidation in inputDegreeOfConsolidations)
{
var trafficLoadDegreeOfConsolidation = new TrafficLoadDegreeOfConsolidation
{
SoilName = degreeOfConsolidation.SoilName,
DegreeOfConsolidation = degreeOfConsolidation.DegreeOfConsolidation
};
dike.TrafficLoadDegreeOfConsolidations.Add(trafficLoadDegreeOfConsolidation);
}
}
}
private static void AddLayers1D(Io.XmlInput.SoilProfile1D inputSoilProfile1D, SoilProfile1D soilProfile1D, SoilList soils)
{
if (inputSoilProfile1D != null)
{
for (var i = 0; i < inputSoilProfile1D.Layers1D.Length; i++)
{
var layer = new SoilLayer1D();
SoilProfile1DLayer1D inputLayer = inputSoilProfile1D.Layers1D[i];
layer.Name = inputLayer.Name;
layer.Soil = soils.GetSoilByName(inputLayer.SoilName);
layer.TopLevel = inputLayer.TopLevel;
layer.IsAquifer = inputLayer.IsAquifer;
layer.WaterpressureInterpolationModel = ConversionHelper.ConvertToWaterpressureInterpolationModel(
inputLayer.WaterpressureInterpolationModel);
soilProfile1D.Layers.Add(layer);
}
}
}
private static void TransferSoilProfiles2D(Io.XmlInput.SoilProfile2D[] inputSoilProfiles2D,
IList dikeSoilProfiles, SoilList soils)
{
if (inputSoilProfiles2D != null)
{
for (var i = 0; i < inputSoilProfiles2D.Length; i++)
{
var soilProfile2D = new SoilProfile2D();
Io.XmlInput.SoilProfile2D inputSoilProfile2D = inputSoilProfiles2D[i];
soilProfile2D.Name = inputSoilProfile2D.Name;
AddPreconsolidationStresses(inputSoilProfile2D, soilProfile2D);
AddLayers2D(inputSoilProfile2D, soilProfile2D, soils);
soilProfile2D.Geometry.Right = soilProfile2D.Geometry.MaxGeometryPointsX;
soilProfile2D.Geometry.Left = soilProfile2D.Geometry.MinGeometryPointsX;
dikeSoilProfiles.Add(soilProfile2D);
}
}
}
private static void AddPreconsolidationStresses(Io.XmlInput.SoilProfile2D inputSoilProfile2D, SoilProfile2D soilProfile2D)
{
if (inputSoilProfile2D.PreconsolidationStresses != null)
{
for (var i = 0; i < inputSoilProfile2D.PreconsolidationStresses.Length; i++)
{
var precon = new PreConsolidationStress();
SoilProfile2DPreconsolidationStress inputPrecon = inputSoilProfile2D.PreconsolidationStresses[i];
precon.Name = inputPrecon.Name;
precon.StressValue = inputPrecon.StressValue;
precon.X = inputPrecon.X;
precon.Z = inputPrecon.Z;
soilProfile2D.PreconsolidationStresses.Add(precon);
}
}
}
internal static void AddLayers2D(Io.XmlInput.SoilProfile2D inputSoilProfile2D, SoilProfile2D soilProfile2D, SoilList soils)
{
if (inputSoilProfile2D != null)
{
for (var i = 0; i < inputSoilProfile2D.Layers2D.Length; i++)
{
var layer = new SoilLayer2D
{
GeometrySurface = new GeometrySurface()
};
SoilProfile2DLayer2D inputLayer = inputSoilProfile2D.Layers2D[i];
layer.Name = inputLayer.SoilName;
layer.Soil = soils.GetSoilByName(inputLayer.SoilName);
layer.IsAquifer = inputLayer.IsAquifer;
layer.WaterpressureInterpolationModel = ConversionHelper.ConvertToWaterpressureInterpolationModel(
inputLayer.WaterpressureInterpolationModel);
// Add OuterLoop
AddOuterLoopToSoilProfile2DFromLayer2D(soilProfile2D.Geometry, inputLayer.Surface.OuterLoop, layer.GeometrySurface.OuterLoop);
// Add InnerLoop when available
if (inputLayer.Surface.Innerloop != null && inputLayer.Surface.Innerloop.Length > 0)
{
layer.GeometrySurface.InnerLoops.Add(new GeometryLoop());
AddInnerLoopToSoilProfile2DFromLayer2D(soilProfile2D.Geometry, inputLayer.Surface.Innerloop, layer.GeometrySurface.InnerLoops[0]);
}
soilProfile2D.Surfaces.Add(layer);
soilProfile2D.Geometry.Surfaces.Add(layer.GeometrySurface);
}
}
}
private static void AddOuterLoopToSoilProfile2DFromLayer2D(GeometryData geometry, SoilProfile2DLayer2DSurfaceOuterPoint[] inputOuterLoop ,
GeometryLoop outputOuterLoop)
{
List inputPoints = new List();
foreach (SoilProfile2DLayer2DSurfaceOuterPoint innerPoint in inputOuterLoop)
{
inputPoints.Add(new Point2D(innerPoint.X, innerPoint.Z));
}
AddLoopToSoilProfile2DFromLayer2D(geometry, outputOuterLoop, inputPoints);
}
private static void AddInnerLoopToSoilProfile2DFromLayer2D(GeometryData geometry,
SoilProfile2DLayer2DSurfaceInnerPoint[] inputInnerLoop,
GeometryLoop outputInnerLoop)
{
List inputPoints = new List();
foreach (SoilProfile2DLayer2DSurfaceInnerPoint innerPoint in inputInnerLoop)
{
inputPoints.Add(new Point2D(innerPoint.X, innerPoint.Z));
}
AddLoopToSoilProfile2DFromLayer2D(geometry, outputInnerLoop, inputPoints);
}
private static void AddLoopToSoilProfile2DFromLayer2D(GeometryData geometry, GeometryLoop outputInnerLoop, List inputPoints)
{
var isStartPoint = true;
var curve = new GeometryCurve();
var firstPoint = new Point2D();
for (var j = 0; j < inputPoints.Count; j++)
{
var point = inputPoints[j];
point = AddPointToSoilProfile2D(geometry, outputInnerLoop, point);
if (isStartPoint)
{
curve.HeadPoint = point;
firstPoint = point;
}
else
{
curve.EndPoint = point;
AddCurveToSoilProfile2D(geometry, outputInnerLoop, curve);
curve = new GeometryCurve();
curve.HeadPoint = point;
}
if (j == inputPoints.Count - 1)
{
curve.EndPoint = firstPoint;
AddCurveToSoilProfile2D(geometry, outputInnerLoop, curve);
}
isStartPoint = false;
}
geometry.Loops.Add(outputInnerLoop);
}
private static Point2D AddPointToSoilProfile2D(GeometryData geometry, GeometryLoop outputLoop, Point2D point)
{
var existingPoint = geometry.GetPointAtLocation(point);
if (existingPoint == null)
{
geometry.Points.Add(point);
outputLoop.Points.Add(point);
return point;
}
else
{
outputLoop.Points.Add(existingPoint);
return existingPoint;
}
}
private static void AddCurveToSoilProfile2D(GeometryData geometry, GeometryLoop outputLoop, GeometryCurve curve)
{
var existingCurve = GeometryHelper.DoesCurveExist(geometry, curve);
if (existingCurve == null)
{
geometry.Curves.Add(curve);
outputLoop.CurveList.Add(curve);
}
else
{
outputLoop.CurveList.Add(existingCurve);
}
}
private static void TransferSegments(Io.XmlInput.Segment[] inputSegments, IList segments)
{
for (var i = 0; i < inputSegments.Length; i++)
{
var segment = new Segment();
Io.XmlInput.Segment inputSegment = inputSegments[i];
segment.Name = inputSegment.Name;
AddSoilProfileProbabilities(inputSegment, segment);
segments.Add(segment);
}
}
private static void AddSoilProfileProbabilities(Io.XmlInput.Segment inputSegment, Segment segment)
{
if (inputSegment.SoilGeometryProbability != null)
{
for (var i = 0; i < inputSegment.SoilGeometryProbability.Length; i++)
{
var soilGeometryProbability = new SoilGeometryProbability();
SegmentSoilGeometryProbability inputSoilGeometryProbability = inputSegment.SoilGeometryProbability[i];
soilGeometryProbability.Probability = inputSoilGeometryProbability.Probability;
if (inputSoilGeometryProbability.SegmentFailureMechanismTypeSpecified)
{
soilGeometryProbability.SegmentFailureMechanismType = ConversionHelper.ConvertToSegmentFailureMechanismSystemType(inputSoilGeometryProbability.SegmentFailureMechanismType);
}
else
{
soilGeometryProbability.SegmentFailureMechanismType = null;
}
soilGeometryProbability.SoilProfileType = ConversionHelper.ConvertToSoilGeometryType(inputSoilGeometryProbability.SoilProfileType);
switch (soilGeometryProbability.SoilProfileType)
{
case SoilProfileType.ProfileType1D:
{
soilGeometryProbability.SoilProfile1DName = inputSoilGeometryProbability.SoilProfileName;
break;
}
case SoilProfileType.ProfileType2D:
{
soilGeometryProbability.SoilProfile2DName = inputSoilGeometryProbability.SoilProfileName;
break;
}
}
segment.SoilProfileProbabilities.Add(soilGeometryProbability);
}
}
}
}