// Copyright (C) Stichting Deltares 2024. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU 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.Dam.Data.Sensors;
using Deltares.DamEngine.Io.XmlInput;
using Deltares.Geotechnics.Soils;
using Deltares.Geotechnics.SurfaceLines;
using Deltares.Standard.Extensions;
using Sensor = Deltares.DamEngine.Io.XmlInput.Sensor;
using SensorLocation = Deltares.DamEngine.Io.XmlInput.SensorLocation;
using Soil = Deltares.DamEngine.Io.XmlInput.Soil;
using SoilProfile1D = Deltares.Geotechnics.Soils.SoilProfile1D;
using SurfaceLine = Deltares.DamEngine.Io.XmlInput.SurfaceLine;
namespace Deltares.Dam.Data.DamEngineIo;
///
/// Create DAM UI project from XML Input object
///
public class FillDamUiFromXmlInput
{
///
/// Creates the dam project data.
///
/// The input.
///
public static DamProjectData CreateDamProjectData(Input input)
{
ValidateInput(input);
var damProjectData = new DamProjectData();
if (input.MaxCalculationCoresSpecified)
{
damProjectData.MaxCalculationCores = input.MaxCalculationCores;
}
damProjectData.WaterBoard = new WaterBoard();
damProjectData.WaterBoard.Dikes = new List();
damProjectData.WaterBoard.Dikes.Add(new Dike());
Dike dike = damProjectData.WaterBoard.Dikes[0];
TransferAnalysisSpecification(input, damProjectData);
TransferStabilityParameters(input, damProjectData);
var localSurfaceLines = new List();
TransferSurfaceLines(input.SurfaceLines, localSurfaceLines);
dike.SoilList = new SoilList();
TransferSoils(input.Soils, dike.SoilList);
TransferSoilProfiles1D(input.SoilProfiles1D, dike.SoilProfiles, dike.SoilList);
TransferSegments(input.Segments, dike.SoilProfiles, damProjectData.WaterBoard.Segments);
TransferLocations(input.Locations, dike.Locations, localSurfaceLines, damProjectData.WaterBoard.Segments);
TransferTrafficLoadDegreeOfConsolidation(input.TrafficLoadDegreeOfConsolidations, dike);
if (input.OperationalInputTimeSeries != null)
{
damProjectData.InputTimeSerieCollection = new TimeSerieCollection();
TransferInputTimeSeries(input.OperationalInputTimeSeries, damProjectData.InputTimeSerieCollection);
}
if (input.SensorData != null)
{
damProjectData.SensorData = new SensorData();
TransferSensorData(input.SensorData, damProjectData.SensorData, dike.Locations);
}
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;
}
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 Sensors.Sensor
{
ID = inputSensor.Id,
Name = inputSensor.Name,
RelativeLocation = inputSensor.RelativeLocation,
Type = ConversionHelper.ConvertToSensorType(inputSensor.SensorType),
PLLineMappings = plLineMappings
});
}
// Transfer sensorgroups
foreach (SensorGroup inputSensorGroup in inputSensorData.SensorGroups)
{
var sensorGroup = new Group();
sensorGroup.ID = inputSensorGroup.Id;
foreach (SensorGroupSensorIds sensorId in inputSensorGroup.SensorIds)
{
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 Sensors.SensorLocation();
sensorLocation.Location = locations.First(l => l.Name.Equals(inputSensorLocation.LocationId));
sensorLocation.Location.SensorLocation = sensorLocation;
sensorLocation.Group = 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(DamEngine.Io.XmlInput.TimeSerie[] inputOperationalInputTimeSeries, TimeSerieCollection timeSerieCollection)
{
foreach (DamEngine.Io.XmlInput.TimeSerie inputTimeSerie in inputOperationalInputTimeSeries)
{
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;
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.FailureMechanismeParamatersMStab = new FailureMechanismeParamatersMStab();
curSpec.FailureMechanismeParamatersMStab.MStabParameters = new MStabParameters();
MStabParameters curStabParamas = curSpec.FailureMechanismeParamatersMStab.MStabParameters;
curStabParamas.SearchMethod = ConversionHelper.ConvertToSearchMethod(input.StabilityParameters.SearchMethod);
curStabParamas.SlipCircleDefinition = new SlipCircleDefinition();
SlipCircleDefinition slipCircleDefinition = curStabParamas.SlipCircleDefinition;
slipCircleDefinition.UpliftVanGridSizeDetermination = ConversionHelper.ConvertToGridDetermination(input.StabilityParameters.UpliftVanGridDetermination);
slipCircleDefinition.BishopSearchAreaDetermination = ConversionHelper.ConvertToGridDetermination(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 NullReferenceException("No input defined");
}
if (input.Locations == null)
{
throw new NullReferenceException("No locations defined in the input");
}
foreach (DamEngine.Io.XmlInput.Location location in input.Locations)
{
if (location.DesignScenarios == null)
{
throw new NullReferenceException("No design scenarios defined in location");
}
}
if (input.SurfaceLines == null)
{
throw new NullReferenceException("No surfacelines defined in the input");
}
foreach (SurfaceLine surfaceLine in input.SurfaceLines)
{
if ((surfaceLine.Points == null) || (surfaceLine.Points.Length < 1))
{
throw new NullReferenceException($"Surfaceline '{surfaceLine.Name}' has no points");
}
}
if (input.Soils == null)
{
throw new NullReferenceException("No soils defined in the input");
}
}
private static void TransferSoils(Soil[] inputSoils, SoilList dikeSoilList)
{
List soils = dikeSoilList.Soils;
for (var i = 0; i < inputSoils.Length; i++)
{
var soil = new Geotechnics.Soils.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.UseDefaultShearStrengthModel = false;
soil.ShearStrengthModel = inputSoil.ShearStrengthModelSpecified ? ConversionHelper.ConvertToShearStrengthModel(inputSoil.ShearStrengthModel) : ShearStrengthModel.CPhi;
if (soil.ShearStrengthModel == ShearStrengthModel.StressTable)
{
soil.StressTable = new StressCurve();
for (var j = 0; j < inputSoil.SigmaTauCurve.Length; j++)
{
SigmaTauCurveSigmaTauPoint point = inputSoil.SigmaTauCurve[j];
soil.StressTable.SigmaTaus.Add(new SigmaTau
{
Sigma = point.Sigma,
Tau = point.Tau
});
}
}
if (soil.ShearStrengthModel == ShearStrengthModel.SuTable)
{
soil.SuTable = new SigmaSuCurve();
for (var j = 0; j < inputSoil.SuTable.Length; j++)
{
SuTableSigmaSuPoint point = inputSoil.SuTable[j];
soil.SuTable.SigmaSus.Add(new SigmaSu()
{
Sigma = point.Sigma,
Su = point.Su
});
}
}
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;
soils.Add(soil);
}
}
private static void TransferSurfaceLines(SurfaceLine[] inputSurfaceLines, IList dikeSurfaceLines)
{
for (var i = 0; i < inputSurfaceLines.Length; i++)
{
SurfaceLine inputSurfaceLine = inputSurfaceLines[i];
SurfaceLine2 surfaceLine = FillDamUiFromXmlHelper.ConvertXmlSurfaceLineToSurfaceLine2(inputSurfaceLine);
dikeSurfaceLines.Add(surfaceLine);
}
}
private static void TransferLocations(DamEngine.Io.XmlInput.Location[] inputLocations, IList dikeLocations, IList dikeSurfaceLines, IList segments)
{
for (var i = 0; i < inputLocations.Length; i++)
{
var location = new Location();
DamEngine.Io.XmlInput.Location inputLocation = inputLocations[i];
LocationWaternetOptions waternetOptions = inputLocation.WaternetOptions;
location.Name = inputLocation.Name;
if (inputLocation.DistanceToEntryPointSpecified)
{
location.DistanceToEntryPoint = inputLocation.DistanceToEntryPoint;
}
location.PLLineCreationMethod = ConversionHelper.ConvertToPhreaticLineCreationMethod(waternetOptions.PhreaticLineCreationMethod);
location.IntrusionVerticalWaterPressure = ConversionHelper.ConvertToIntrusionVerticalWaterPressure(waternetOptions.IntrusionVerticalWaterPressure);
location.DampingFactorPL3 = waternetOptions.DampingFactorPl3;
location.DampingFactorPL4 = waternetOptions.DampingFactorPl4;
location.PenetrationLength = waternetOptions.PenetrationLength;
location.SlopeDampingPiezometricHeightPolderSide = waternetOptions.SlopeDampingFactor;
SurfaceLine2 surfaceLine = dikeSurfaceLines.First(n => n.Name.Equals(inputLocation.SurfaceLineName));
location.LocalXZSurfaceLine2 = surfaceLine;
Segment 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 Scenario();
LocationDesignScenario inputLocationDesignScenario = inputLocation.DesignScenarios[j];
designScenario.LocationScenarioID = inputLocationDesignScenario.Id;
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.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;
designScenario.PolderLevel = inputLocationDesignScenario.PolderLevel;
designScenario.HeadPl2 = (inputLocationDesignScenario.HeadPl2Specified ? inputLocationDesignScenario.HeadPl2 : null);
location.Scenarios.Add(designScenario);
}
}
location.DikeEmbankmentMaterial = inputLocation.DikeEmbankmentMaterial;
if (inputLocation.StabilityOptions != null)
{
location.StabilityZoneType = ConversionHelper.ConvertToZoneType(inputLocation.StabilityOptions.ZoneType);
if (inputLocation.StabilityOptions.ForbiddenZoneFactorSpecified)
{
location.ForbiddenZoneFactor = inputLocation.StabilityOptions.ForbiddenZoneFactor;
}
if (inputLocation.StabilityOptions.TrafficLoadSpecified)
{
location.TrafficLoad = inputLocation.StabilityOptions.TrafficLoad;
}
if (inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidationSpecified)
{
location.TL_DegreeOfConsolidation = inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidation;
}
if (inputLocation.StabilityOptions.MinimumCircleDepthSpecified)
{
location.MinimalCircleDepth = inputLocation.StabilityOptions.MinimumCircleDepth;
}
}
// 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);
}
dikeLocations.Add(location);
}
}
private static void TransferTrafficLoadDegreeOfConsolidation(IList inputTrafficLoadDegreeOfConsolidations, Dike dike)
{
if (inputTrafficLoadDegreeOfConsolidations != null)
{
dike.TrafficLoadDegreeOfConsolidations = new List(inputTrafficLoadDegreeOfConsolidations.Count);
foreach (InputTrafficLoadDegreeOfConsolidation inputDegreeOfConsolidation in inputTrafficLoadDegreeOfConsolidations)
{
var trafficLoadDegreeOfConsolidation = new TrafficLoadDegreeOfConsolidation
{
SoilName = inputDegreeOfConsolidation.SoilName,
DegreeOfConsolidation = inputDegreeOfConsolidation.DegreeOfConsolidation
};
dike.TrafficLoadDegreeOfConsolidations.Add(trafficLoadDegreeOfConsolidation);
}
}
}
private static void TransferSoilProfiles1D(DamEngine.Io.XmlInput.SoilProfile1D[] inputSoilProfiles1D,
IList dikeSoilProfiles, SoilList soils)
{
if (inputSoilProfiles1D != null)
{
for (var i = 0; i < inputSoilProfiles1D.Length; i++)
{
var soilProfile1D = new SoilProfile1D();
DamEngine.Io.XmlInput.SoilProfile1D inputSoilProfile1D = inputSoilProfiles1D[i];
soilProfile1D.Name = inputSoilProfile1D.Name;
soilProfile1D.BottomLevel = inputSoilProfile1D.BottomLevel;
AddLayers1D(inputSoilProfile1D, soilProfile1D, soils);
dikeSoilProfiles.Add(soilProfile1D);
}
}
}
private static void AddLayers1D(DamEngine.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.Id = 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 TransferSegments(DamEngine.Io.XmlInput.Segment[] inputSegments, IList dikeSoilProfiles, IList segments)
{
for (var i = 0; i < inputSegments.Length; i++)
{
var segment = new Segment();
DamEngine.Io.XmlInput.Segment inputSegment = inputSegments[i];
segment.Name = inputSegment.Name;
AddSoilProfileProbabilities(inputSegment, dikeSoilProfiles, segment);
segments.Add(segment);
}
}
private static void AddSoilProfileProbabilities(DamEngine.Io.XmlInput.Segment inputSegment, IList dikeSoilProfiles, Segment segment)
{
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.ConvertToSegmentFailureMechanismType(inputSoilGeometryProbability.SegmentFailureMechanismType);
}
else
{
soilGeometryProbability.SegmentFailureMechanismType = null;
}
if (inputSoilGeometryProbability.SoilProfileType == 0)
{
soilGeometryProbability.SoilProfile = FindSoilProfile1DByName(dikeSoilProfiles, inputSoilGeometryProbability.SoilProfileName);
}
else
{
soilGeometryProbability.SoilGeometry2DName = inputSoilGeometryProbability.SoilProfileName;
}
SoilProfileType expectedSoilProfileType = ConversionHelper.ConvertToSoilProfileType(inputSoilGeometryProbability.SoilProfileType);
if (soilGeometryProbability.SoilProfileType != expectedSoilProfileType)
{
throw new ConversionException(typeof(SegmentSoilGeometryProbability), soilGeometryProbability.SoilProfileType);
}
segment.SoilProfileProbabilities.Add(soilGeometryProbability);
}
}
}