// 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;
using Deltares.DamEngine.Io.XmlInput;
using Location = Deltares.DamEngine.Data.General.Location;
using Segment = Deltares.DamEngine.Data.General.Segment;
using Sensor = Deltares.DamEngine.Data.General.Sensors.Sensor;
using SensorGroup = Deltares.DamEngine.Io.XmlInput.SensorGroup;
using SensorLocation = Deltares.DamEngine.Io.XmlInput.SensorLocation;
using Soil = Deltares.DamEngine.Data.Geotechnics.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;
public class FillXmlInputFromDam
{
///
/// Creates the input from Dam data.
///
/// The dam project data.
///
public static Input CreateInput(DamProjectData damProjectData)
{
ValidateDamProjectData(damProjectData);
var input = new Input();
input.ProjectPath = damProjectData.ProjectPath;
input.CalculationMap = damProjectData.CalculationMap;
input.MaxCalculationCoresSpecified = true;
input.MaxCalculationCores = damProjectData.MaxCalculationCores;
TransferAnalysisSpecification(damProjectData, input);
TransferStabilityParameters(damProjectData, input);
Dike dike = damProjectData.Dike;
input.Locations = new Io.XmlInput.Location[dike.Locations.Count];
TransferLocations(dike.Locations, input.Locations);
input.SurfaceLines = new SurfaceLine[dike.SurfaceLines2.Count];
TransferSurfaceLines(dike.SurfaceLines2, input.SurfaceLines);
input.Soils = new Io.XmlInput.Soil[dike.SoilList.Soils.Count];
TransferSoils(dike.SoilList.Soils, input.Soils);
TransferTrafficLoadDegreeOfConsolidation(dike.TrafficLoadDegreeOfConsolidations, input);
if (dike.SoilProfiles != null)
{
int profilesCount = dike.SoilProfiles.Count;
input.SoilProfiles1D = new Io.XmlInput.SoilProfile1D[profilesCount];
TransferSoilProfiles1D(dike.SoilProfiles, input.SoilProfiles1D);
}
if (dike.SoilProfiles2D != null)
{
int profilesCount = dike.SoilProfiles2D.Count;
input.SoilProfiles2D = new Io.XmlInput.SoilProfile2D[profilesCount];
TransferSoilProfiles2D(dike.SoilProfiles2D, input.SoilProfiles2D);
}
if (damProjectData.Segments != null)
{
input.Segments = new Io.XmlInput.Segment[damProjectData.Segments.Count];
TransferSegments(damProjectData.Segments, input.Segments);
}
if (dike.InputTimeSerieCollection != null)
{
input.OperationalInputTimeSeries = new TimeSerie[dike.InputTimeSerieCollection.Series.Count];
TransferInputTimeSeries(dike.InputTimeSerieCollection, input.OperationalInputTimeSeries);
}
if (damProjectData.SensorData != null)
{
input.SensorData = new InputSensorData();
TransferSensorData(damProjectData.SensorData, input.SensorData);
}
return input;
}
private static void TransferSensorData(SensorData sensorData, InputSensorData inputSensorData)
{
// Transfer sensorgroups
var sensorGroupIndex = 0;
inputSensorData.SensorGroups = new SensorGroup[sensorData.SensorGroups.Count];
foreach (Data.General.Sensors.SensorGroup sensorGroup in sensorData.SensorGroups)
{
var inputSensorGroup = new SensorGroup();
inputSensorGroup.SensorIds = new SensorGroupSensorIds[sensorGroup.SensorCount];
inputSensorGroup.Id = sensorGroup.ID;
var sensorIdIndex = 0;
foreach (Sensor sensor in sensorGroup.SensorArray)
{
inputSensorGroup.SensorIds[sensorIdIndex] = new SensorGroupSensorIds
{
SensorId = sensor.ID
};
sensorIdIndex++;
}
inputSensorData.SensorGroups[sensorGroupIndex] = inputSensorGroup;
sensorGroupIndex++;
}
// Transfer sensorlocations
var senserLocationIndex = 0;
inputSensorData.SensorLocations = new SensorLocation[sensorData.SensorLocations.Count];
foreach (Data.General.Sensors.SensorLocation sensorLocation in sensorData.SensorLocations)
{
var inputSensorLocation = new SensorLocation();
inputSensorLocation.GroupId = sensorLocation.GroupId;
inputSensorLocation.LocationId = sensorLocation.LocationName;
inputSensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder);
inputSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder);
inputSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver);
inputSensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside);
inputSensorLocation.SourceTypePl1WaterLevelAtRiver = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl1WaterLevelAtRiver);
inputSensorLocation.SourceTypePl1WaterLevelAtPolder = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl1WaterLevelAtPolder);
inputSensorLocation.SourceTypePl3 = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl3);
inputSensorLocation.SourceTypePl4 = ConversionHelper.ConvertToInputDataSourceTypeSensors(sensorLocation.SourceTypePl4);
inputSensorData.SensorLocations[senserLocationIndex] = inputSensorLocation;
senserLocationIndex++;
}
// Transfer sensors
inputSensorData.Sensors = new Io.XmlInput.Sensor[sensorData.Sensors.Count];
var sensorIndex = 0;
foreach (Sensor sensor in sensorData.Sensors)
{
var inputSensor = new Io.XmlInput.Sensor();
inputSensor.Id = sensor.ID;
inputSensor.Name = sensor.Name;
inputSensor.RelativeLocation = sensor.RelativeLocation;
inputSensor.SensorType = ConversionHelper.ConvertToInputSensorType(sensor.SensorType);
inputSensor.PlLineMapping = new SensorPlLineMapping[sensor.PlLineMappings.Length];
var mappingIndex = 0;
foreach (PlLineType plLineMapping in sensor.PlLineMappings)
{
inputSensor.PlLineMapping[mappingIndex] = new SensorPlLineMapping
{
PLineType = ConversionHelper.ConvertToInputPlLineType(plLineMapping)
};
mappingIndex++;
}
inputSensorData.Sensors[sensorIndex] = inputSensor;
sensorIndex++;
}
}
private static void TransferInputTimeSeries(TimeSerieCollection inputTimeSerieCollection, TimeSerie[] operationalInputTimeSeries)
{
var timeSerieIndex = 0;
foreach (Data.General.TimeSeries.TimeSerie timeSerie in inputTimeSerieCollection.Series)
{
var inputTimeSerie = new TimeSerie();
inputTimeSerie.Entries = new TimeSerieEntries();
inputTimeSerie.Entries.TimeSerieEntry = new TimeSerieEntriesTimeSerieEntry[timeSerie.Entries.Count];
inputTimeSerie.LocationId = timeSerie.LocationId;
inputTimeSerie.ParameterId = timeSerie.ParameterId;
inputTimeSerie.ForecastDateTime = timeSerie.ForecastDateTime;
inputTimeSerie.StartDateTime = timeSerie.StartDateTime;
inputTimeSerie.EndDateTime = timeSerie.EndDateTime;
inputTimeSerie.MissVal = timeSerie.MissVal;
inputTimeSerie.Units = timeSerie.Units;
var timeSerieEntryIndex = 0;
foreach (TimeSerieEntry timestepEntry in timeSerie.Entries)
{
var timeStep = new TimeSerieEntriesTimeSerieEntry
{
DateTime = timestepEntry.DateTime,
Value = timestepEntry.Value
};
inputTimeSerie.Entries.TimeSerieEntry[timeSerieEntryIndex] = timeStep;
timeSerieEntryIndex++;
}
operationalInputTimeSeries[timeSerieIndex] = inputTimeSerie;
timeSerieIndex++;
}
}
private static void TransferTrafficLoadDegreeOfConsolidation(IList degreeOfConsolidationDictionary, Input input)
{
InputTrafficLoadDegreeOfConsolidation[] inputTrafficLoadDegreeOfConsolidations;
if (degreeOfConsolidationDictionary != null && degreeOfConsolidationDictionary.Count > 0)
{
inputTrafficLoadDegreeOfConsolidations = new InputTrafficLoadDegreeOfConsolidation[degreeOfConsolidationDictionary.Count];
var index = 0;
foreach (TrafficLoadDegreeOfConsolidation degreeOfConsolidation in degreeOfConsolidationDictionary)
{
inputTrafficLoadDegreeOfConsolidations[index] = new InputTrafficLoadDegreeOfConsolidation
{
SoilName = degreeOfConsolidation.SoilName,
DegreeOfConsolidation = degreeOfConsolidation.DegreeOfConsolidation
};
index++;
}
}
else
{
inputTrafficLoadDegreeOfConsolidations = null;
}
input.TrafficLoadDegreeOfConsolidations = inputTrafficLoadDegreeOfConsolidations;
}
private static void TransferAnalysisSpecification(DamProjectData damProjectData, Input input)
{
input.DamProjectType = ConversionHelper.ConvertToInputDamProjectType(damProjectData.DamProjectType);
input.FailureMechanismSystemType = ConversionHelper.ConvertToInputFailureMechanismSystemType(damProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismSystemType);
input.AnalysisTypeSpecified = (input.DamProjectType == InputDamProjectType.Design);
if (input.AnalysisTypeSpecified)
{
input.AnalysisType = ConversionHelper.ConvertToInputAnalysisType(DamProjectCalculationSpecification.SelectedAnalysisType);
}
input.PipingModelTypeSpecified = (input.FailureMechanismSystemType == InputFailureMechanismSystemType.Piping);
if (input.PipingModelTypeSpecified)
{
input.PipingModelType = ConversionHelper.ConvertToInputPipingModelType(damProjectData.DamProjectCalculationSpecification.CurrentSpecification.PipingModelType);
}
input.StabilityModelTypeSpecified = (input.FailureMechanismSystemType == InputFailureMechanismSystemType.StabilityInside) || (input.FailureMechanismSystemType == InputFailureMechanismSystemType.StabilityOutside);
if (input.StabilityModelTypeSpecified)
{
input.StabilityModelType = ConversionHelper.ConvertToInputStabilityModelType(damProjectData.DamProjectCalculationSpecification.CurrentSpecification.StabilityModelType);
}
}
private static void TransferStabilityParameters(DamProjectData damProjectData, Input input)
{
if (damProjectData.DamProjectCalculationSpecification != null && damProjectData.DamProjectCalculationSpecification.CurrentSpecification != null)
{
DamFailureMechanismeCalculationSpecification curSpec = damProjectData.DamProjectCalculationSpecification.CurrentSpecification;
if (curSpec.FailureMechanismParametersMStab != null && curSpec.FailureMechanismParametersMStab.MStabParameters != null)
{
input.StabilityParameters = new StabilityParameters();
input.StabilityParameters.SearchMethod = ConversionHelper.ConvertToInputSearchMethod(curSpec.FailureMechanismParametersMStab.MStabParameters.SearchMethod);
SlipCircleDefinition slipCircleDefinition = curSpec.FailureMechanismParametersMStab.MStabParameters.SlipCircleDefinition;
if (slipCircleDefinition != null)
{
input.StabilityParameters.UpliftVanGridDetermination = ConversionHelper.ConvertToInputUpliftVanGridDetermination(slipCircleDefinition.UpliftVanGridSizeDetermination);
input.StabilityParameters.BishopSearchAreaDetermination = ConversionHelper.ConvertToInputBishopSearchAreaDetermination(slipCircleDefinition.BishopSearchAreaDetermination);
input.StabilityParameters.BishopTangentLinesDistanceSpecified = true;
input.StabilityParameters.BishopTangentLinesDistance = slipCircleDefinition.BishopTangentLinesDistance;
input.StabilityParameters.BishopGridVerticalPointsCountSpecified = true;
input.StabilityParameters.BishopGridVerticalPointsCount = slipCircleDefinition.BishopGridVerticalPointCount;
input.StabilityParameters.BishopGridVerticalPointsDistanceSpecified = true;
input.StabilityParameters.BishopGridVerticalPointsDistance = slipCircleDefinition.BishopGridVerticalPointDistance;
input.StabilityParameters.BishopGridHorizontalPointsCountSpecified = true;
input.StabilityParameters.BishopGridHorizontalPointsCount = slipCircleDefinition.BishopGridHorizontalPointCount;
input.StabilityParameters.BishopGridHorizontalPointsDistanceSpecified = true;
input.StabilityParameters.BishopGridHorizontalPointsDistance = slipCircleDefinition.BishopGridHorizontalPointDistance;
input.StabilityParameters.UpliftVanTangentLinesDefinitionSpecified = true;
input.StabilityParameters.UpliftVanTangentLinesDefinition = ConversionHelper.ConvertToInputTangentLinesDefinition(slipCircleDefinition.UpliftVanTangentLinesDefinition);
input.StabilityParameters.UpliftVanTangentLinesDistanceSpecified = true;
input.StabilityParameters.UpliftVanTangentLinesDistance = slipCircleDefinition.UpliftVanTangentLinesDistance;
input.StabilityParameters.UpliftVanGridLeftVerticalPointsCountSpecified = true;
input.StabilityParameters.UpliftVanGridLeftVerticalPointsCount = slipCircleDefinition.UpliftVanLeftGridVerticalPointCount;
input.StabilityParameters.UpliftVanGridLeftVerticalPointsDistanceSpecified = true;
input.StabilityParameters.UpliftVanGridLeftVerticalPointsDistance = slipCircleDefinition.UpliftVanLeftGridVerticalPointDistance;
input.StabilityParameters.UpliftVanGridLeftHorizontalPointsCountSpecified = true;
input.StabilityParameters.UpliftVanGridLeftHorizontalPointsCount = slipCircleDefinition.UpliftVanLeftGridHorizontalPointCount;
input.StabilityParameters.UpliftVanGridLeftHorizontalPointsDistanceSpecified = true;
input.StabilityParameters.UpliftVanGridLeftHorizontalPointsDistance = slipCircleDefinition.UpliftVanLeftGridHorizontalPointDistance;
input.StabilityParameters.UpliftVanGridRightVerticalPointsCountSpecified = true;
input.StabilityParameters.UpliftVanGridRightVerticalPointsCount = slipCircleDefinition.UpliftVanRightGridVerticalPointCount;
input.StabilityParameters.UpliftVanGridRightVerticalPointsDistanceSpecified = true;
input.StabilityParameters.UpliftVanGridRightVerticalPointsDistance = slipCircleDefinition.UpliftVanRightGridVerticalPointDistance;
input.StabilityParameters.UpliftVanGridRightHorizontalPointsCountSpecified = true;
input.StabilityParameters.UpliftVanGridRightHorizontalPointsCount = slipCircleDefinition.UpliftVanRightGridHorizontalPointCount;
input.StabilityParameters.UpliftVanGridRightHorizontalPointsDistanceSpecified = true;
input.StabilityParameters.UpliftVanGridRightHorizontalPointsDistance = slipCircleDefinition.UpliftVanRightGridHorizontalPointDistance;
}
}
}
}
private static void ValidateDamProjectData(DamProjectData damProjectData)
{
if (damProjectData.Dike == null)
{
throw new ArgumentNullException(Resources.NoDikeInProject);
}
if (damProjectData.Dike.Locations == null)
{
throw new ArgumentNullException(Resources.NoLocationsInProject);
}
foreach (Location location in damProjectData.Dike.Locations)
{
if (location.Scenarios == null)
{
throw new ArgumentNullException(Resources.NoDesignScenariosInLocationProject);
}
}
if (damProjectData.Dike.SurfaceLines2 == null)
{
throw new ArgumentNullException(Resources.NoSurfaceLinesInProject);
}
foreach (SurfaceLine2 surfaceLine in damProjectData.Dike.SurfaceLines2)
{
if ((surfaceLine.CharacteristicPoints == null) || (surfaceLine.CharacteristicPoints.Count < 1))
{
throw new ArgumentNullException(string.Format(Resources.NoCharacteristicPointsInSurfaceLineProject, surfaceLine.Name));
}
if ((surfaceLine.Geometry == null) || (surfaceLine.Geometry.Count < 2))
{
throw new ArgumentNullException(string.Format(Resources.NoPointsInSurfaceLineProject, surfaceLine.Name));
}
}
if (damProjectData.Dike.SoilList == null)
{
throw new ArgumentNullException(Resources.NoSoilsInProject);
}
if (damProjectData.Dike.SoilList.Soils == null)
{
throw new ArgumentNullException(Resources.NoSoilsInProject);
}
if (damProjectData.Dike.SoilProfiles == null)
{
throw new ArgumentNullException(Resources.NoSoilProfiles1DInProject);
}
// Check for invalid Id names
foreach (Location location in damProjectData.Dike.Locations)
{
if (!IdValidator.IsCorrectName(location.Name))
{
throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.Location, location.Name));
}
}
foreach (Segment segment in damProjectData.Segments)
{
if (!IdValidator.IsCorrectName(segment.Name))
{
throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.Segment, segment.Name));
}
}
foreach (SurfaceLine2 surfaceLine2 in damProjectData.Dike.SurfaceLines2)
{
if (!IdValidator.IsCorrectName(surfaceLine2.Name))
{
throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.SurfaceLine, surfaceLine2.Name));
}
}
foreach (SoilProfile1D soilProfile in damProjectData.Dike.SoilProfiles)
{
if (!IdValidator.IsCorrectName(soilProfile.Name))
{
throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.SoilProfile1D, soilProfile.Name));
}
}
foreach (SoilProfile2D soilProfile2D in damProjectData.Dike.SoilProfiles2D)
{
if (!IdValidator.IsCorrectName(soilProfile2D.Name))
{
throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.SoilProfile2D, soilProfile2D.Name));
}
}
foreach (Soil soil in damProjectData.Dike.SoilList.Soils)
{
if (!IdValidator.IsCorrectName(soil.Name))
{
throw new IdValidatorException(string.Format(Resources.NoValidId, Resources.Soil, soil.Name));
}
}
}
private static void TransferSoils(List soils, Io.XmlInput.Soil[] inputSoils)
{
for (var i = 0; i < soils.Count; i++)
{
Soil soil = soils[i];
var inputSoil = new Io.XmlInput.Soil();
inputSoil.Name = soil.Name;
inputSoil.AbovePhreaticLevelSpecified = !double.IsNaN(soil.AbovePhreaticLevel);
inputSoil.AbovePhreaticLevel = soil.AbovePhreaticLevel;
inputSoil.BelowPhreaticLevelSpecified = !double.IsNaN(soil.BelowPhreaticLevel);
inputSoil.BelowPhreaticLevel = soil.BelowPhreaticLevel;
inputSoil.DiameterD70Specified = !double.IsNaN(soil.DiameterD70);
inputSoil.DiameterD70 = soil.DiameterD70;
inputSoil.PermeabKxSpecified = !double.IsNaN(soil.PermeabKx);
inputSoil.PermeabKx = soil.PermeabKx;
inputSoil.ShearStrengthModelSpecified = (soil.ShearStrengthModel != null);
if (inputSoil.ShearStrengthModelSpecified)
{
inputSoil.ShearStrengthModel = ConversionHelper.ConvertToSoilShearStrengthModel(soil.ShearStrengthModel.Value);
}
inputSoil.CohesionSpecified = !double.IsNaN(soil.Cohesion);
inputSoil.Cohesion = soil.Cohesion;
inputSoil.FrictionAngleSpecified = !double.IsNaN(soil.FrictionAngle);
inputSoil.FrictionAngle = soil.FrictionAngle;
inputSoil.OcrSpecified = !double.IsNaN(soil.Ocr);
inputSoil.Ocr = soil.Ocr;
inputSoil.StrengthIncreaseExponentSpecified = !double.IsNaN(soil.StrengthIncreaseExponent);
inputSoil.StrengthIncreaseExponent = soil.StrengthIncreaseExponent;
inputSoil.RatioCuPcSpecified = !double.IsNaN(soil.RatioCuPc);
inputSoil.RatioCuPc = soil.RatioCuPc;
inputSoil.PopSpecified = !double.IsNaN(soil.PoP);
inputSoil.Pop = soil.PoP;
TransferSigmaTauCurves(soil, inputSoil);
TransferSuTables(soil, inputSoil);
inputSoils[i] = inputSoil;
}
}
private static void TransferSuTables(Soil soil, Io.XmlInput.Soil inputSoil)
{
if (soil.SuTableCurve == null)
{
return;
}
inputSoil.SuTable = new SuTableSigmaSuPoint[soil.SuTableCurve.Points.Count];
for (var j = 0; j < soil.SuTableCurve.Points.Count; j++)
{
inputSoil.SuTable[j] = new SuTableSigmaSuPoint
{
Sigma = soil.SuTableCurve.Points[j].Sigma,
Su = soil.SuTableCurve.Points[j].Su
};
}
}
private static void TransferSigmaTauCurves(Soil soil, Io.XmlInput.Soil inputSoil)
{
if (soil.SigmaTauCurve == null)
{
return;
}
inputSoil.SigmaTauCurve = new SigmaTauCurveSigmaTauPoint[soil.SigmaTauCurve.Points.Count];
for (var j = 0; j < soil.SigmaTauCurve.Points.Count; j++)
{
inputSoil.SigmaTauCurve[j] = new SigmaTauCurveSigmaTauPoint
{
Sigma = soil.SigmaTauCurve.Points[j].Sigma,
Tau = soil.SigmaTauCurve.Points[j].Tau
};
}
}
private static void TransferSurfaceLines(IList dikeSurfaceLines, SurfaceLine[] inputSurfaceLines)
{
for (var i = 0; i < dikeSurfaceLines.Count; i++)
{
SurfaceLine2 surfaceLine = dikeSurfaceLines[i];
var inputSurfaceLine = new SurfaceLine();
inputSurfaceLine.Name = surfaceLine.Name;
inputSurfaceLine.Points = new SurfaceLinePoint[surfaceLine.CharacteristicPoints.Count];
for (var j = 0; j < surfaceLine.CharacteristicPoints.Count; j++)
{
CharacteristicPoint characteristicPoint = surfaceLine.CharacteristicPoints[j];
var inputPoint = new SurfaceLinePoint
{
PointType = ConversionHelper.ConvertToInputPointType(characteristicPoint.CharacteristicPointType),
X = characteristicPoint.Point.X,
Z = characteristicPoint.Point.Z
};
inputSurfaceLine.Points[j] = inputPoint;
}
inputSurfaceLines[i] = inputSurfaceLine;
}
}
private static void TransferLocations(IList dikeLocations, Io.XmlInput.Location[] inputLocations)
{
int locationCount = dikeLocations.Count;
for (var i = 0; i < locationCount; i++)
{
Location location = dikeLocations[i];
var inputLocation = new Io.XmlInput.Location();
inputLocation.Name = location.Name;
inputLocation.DistanceToEntryPoint = location.DistanceToEntryPoint;
inputLocation.DistanceToEntryPointSpecified = true;
inputLocation.SurfaceLineName = location.SurfaceLine.Name;
inputLocation.SegmentName = location.Segment.Name;
var waternetOptions = new LocationWaternetOptions();
waternetOptions.PhreaticLineCreationMethod = ConversionHelper.ConvertToInputPhreaticLineCreationMethod(location.ModelParametersForPlLines.PlLineCreationMethod);
waternetOptions.IntrusionVerticalWaterPressure = ConversionHelper.ConvertToInputIntrusionVerticalWaterPressure(location.IntrusionVerticalWaterPressure ?? IntrusionVerticalWaterPressureType.Standard);
waternetOptions.DampingFactorPl3 = location.ModelParametersForPlLines.DampingFactorPl3;
waternetOptions.DampingFactorPl4 = location.ModelParametersForPlLines.DampingFactorPl4;
waternetOptions.PenetrationLength = location.ModelParametersForPlLines.PenetrationLength;
waternetOptions.SlopeDampingFactor = location.SlopeDampingPiezometricHeightPolderSide;
inputLocation.WaternetOptions = waternetOptions;
// Design options
var designOptions = new LocationDesignOptions();
designOptions.RedesignDikeHeight = location.RedesignDikeHeight;
designOptions.RedesignDikeShoulder = location.RedesignDikeShoulder;
designOptions.ShoulderEmbankmentMaterial = location.ShoulderEmbankmentMaterial;
designOptions.StabilityShoulderGrowSlope = location.StabilityShoulderGrowSlope;
designOptions.StabilityShoulderGrowDeltaX = location.StabilityShoulderGrowDeltaX;
designOptions.StabilitySlopeAdaptionDeltaX = location.StabilitySlopeAdaptionDeltaX;
designOptions.SlopeAdaptionStartCotangent = location.SlopeAdaptionStartCotangent;
designOptions.SlopeAdaptionEndCotangent = location.SlopeAdaptionEndCotangent;
designOptions.SlopeAdaptionStepCotangent = location.SlopeAdaptionStepCotangent;
designOptions.NewDikeTopWidthSpecified = location.UseNewDikeTopWidth;
designOptions.NewDikeTopWidth = location.NewDikeTopWidth;
designOptions.NewDikeSlopeInsideSpecified = location.UseNewDikeSlopeInside;
designOptions.NewDikeSlopeInside = location.NewDikeSlopeInside;
designOptions.NewDikeSlopeOutsideSpecified = location.UseNewDikeSlopeOutside;
designOptions.NewDikeSlopeOutside = location.NewDikeSlopeOutside;
designOptions.NewShoulderTopSlopeSpecified = location.UseNewShoulderTopSlope;
designOptions.NewShoulderTopSlope = location.NewShoulderTopSlope;
designOptions.NewShoulderBaseSlopeSpecified = location.UseNewShoulderBaseSlope;
designOptions.NewShoulderBaseSlope = location.NewShoulderBaseSlope;
designOptions.NewMaxHeightShoulderAsFractionSpecified = location.UseNewMaxHeightShoulderAsFraction;
designOptions.NewMaxHeightShoulderAsFraction = location.NewMaxHeightShoulderAsFraction;
designOptions.NewMinDistanceDikeToeStartDitchSpecified = location.UseNewMinDistanceDikeToeStartDitch;
designOptions.NewMinDistanceDikeToeStartDitch = location.NewMinDistanceDikeToeStartDitch;
designOptions.UseNewDitchDefinition = location.UseNewDitchDefinition;
designOptions.NewWidthDitchBottomSpecified = location.UseNewDitchDefinition;
designOptions.NewWidthDitchBottom = location.NewWidthDitchBottom;
designOptions.NewSlopeAngleDitchSpecified = location.UseNewDitchDefinition;
designOptions.NewSlopeAngleDitch = location.NewSlopeAngleDitch;
designOptions.NewDepthDitchSpecified = location.UseNewDitchDefinition;
designOptions.NewDepthDitch = location.NewDepthDitch;
designOptions.StabilityDesignMethod = ConversionHelper.ConvertToInputStabilityDesignMethod(location.StabilityDesignMethod);
inputLocation.DesignOptions = designOptions;
inputLocation.DesignScenarios = new LocationDesignScenario[location.Scenarios.Count];
for (var j = 0; j < location.Scenarios.Count; j++)
{
DesignScenario designScenario = location.Scenarios[j];
var inputDesignScenario = new LocationDesignScenario();
inputDesignScenario.RiverLevel = designScenario.RiverLevel;
inputDesignScenario.Id = designScenario.LocationScenarioID;
inputDesignScenario.PolderLevel = designScenario.PolderLevel;
inputDesignScenario.RiverLevelLowSpecified = designScenario.RiverLevelLow.HasValue;
inputDesignScenario.RiverLevelLow = designScenario.RiverLevelLow ?? 0.0;
inputDesignScenario.DikeTableHeightSpecified = designScenario.DikeTableHeight.HasValue;
inputDesignScenario.DikeTableHeight = designScenario.DikeTableHeight ?? 0.0;
inputDesignScenario.PlLineOffsetBelowDikeTopAtRiver = designScenario.PlLineOffsetBelowDikeTopAtRiver;
inputDesignScenario.PlLineOffsetBelowDikeTopAtPolder = designScenario.PlLineOffsetBelowDikeTopAtPolder;
inputDesignScenario.PlLineOffsetBelowShoulderBaseInside = designScenario.PlLineOffsetBelowShoulderBaseInside;
inputDesignScenario.PlLineOffsetBelowDikeToeAtPolder = designScenario.PlLineOffsetBelowDikeToeAtPolder;
inputDesignScenario.PlLineOffsetBelowDikeCrestMiddleSpecified = designScenario.UsePlLineOffsetBelowDikeCrestMiddle.Value;
inputDesignScenario.PlLineOffsetBelowDikeCrestMiddle = designScenario.PlLineOffsetBelowDikeCrestMiddle.Value;
inputDesignScenario.PlLineOffsetFactorBelowShoulderCrestSpecified = designScenario.UsePlLineOffsetFactorBelowShoulderCrest.Value;
inputDesignScenario.PlLineOffsetFactorBelowShoulderCrest = designScenario.PlLineOffsetFactorBelowShoulderCrest.Value;
inputDesignScenario.HeadPl2Specified = designScenario.HeadPl2.HasValue;
inputDesignScenario.HeadPl2 = designScenario.HeadPl2 ?? 0.0;
inputDesignScenario.HeadPl3Specified = designScenario.HeadPl3.HasValue;
inputDesignScenario.HeadPl3 = designScenario.HeadPl3 ?? 0.0;
inputDesignScenario.HeadPl4Specified = designScenario.HeadPl4.HasValue;
inputDesignScenario.HeadPl4 = designScenario.HeadPl4 ?? 0.0;
inputDesignScenario.UpliftCriterionStability = designScenario.UpliftCriterionStability;
inputDesignScenario.UpliftCriterionPiping = designScenario.UpliftCriterionPiping;
inputDesignScenario.RequiredSafetyFactorStabilityInnerSlope = designScenario.RequiredSafetyFactorStabilityInnerSlope;
inputDesignScenario.RequiredSafetyFactorStabilityOuterSlope = designScenario.RequiredSafetyFactorStabilityOuterSlope;
inputDesignScenario.RequiredSafetyFactorPiping = designScenario.RequiredSafetyFactorPiping;
inputLocation.DesignScenarios[j] = inputDesignScenario;
}
inputLocation.DikeEmbankmentMaterial = location.DikeEmbankmentMaterial;
if (location.StabilityOptions != null)
{
inputLocation.StabilityOptions = new LocationStabilityOptions
{
ZoneType = ConversionHelper.ConvertToInputZoneType(location.StabilityOptions.StabilityZoneType),
ForbiddenZoneFactorSpecified = location.StabilityOptions.ForbiddenZoneFactor.HasValue
};
if (inputLocation.StabilityOptions.ForbiddenZoneFactorSpecified)
{
inputLocation.StabilityOptions.ForbiddenZoneFactor = location.StabilityOptions.ForbiddenZoneFactor.Value;
}
inputLocation.StabilityOptions.TrafficLoadSpecified = location.StabilityOptions.TrafficLoad.HasValue;
if (inputLocation.StabilityOptions.TrafficLoadSpecified)
{
inputLocation.StabilityOptions.TrafficLoad = location.StabilityOptions.TrafficLoad.Value;
}
inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidationSpecified = location.StabilityOptions.TrafficLoadDegreeOfConsolidation.HasValue;
if (inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidationSpecified)
{
inputLocation.StabilityOptions.TrafficLoadDegreeOfConsolidation = location.StabilityOptions.TrafficLoadDegreeOfConsolidation.Value;
}
inputLocation.StabilityOptions.MinimumCircleDepthSpecified = location.StabilityOptions.MinimalCircleDepth.HasValue;
if (inputLocation.StabilityOptions.MinimumCircleDepthSpecified)
{
inputLocation.StabilityOptions.MinimumCircleDepth = location.StabilityOptions.MinimalCircleDepth.Value;
}
}
inputLocations[i] = inputLocation;
}
}
private static void TransferSoilProfiles1D(IList dikeSoilProfiles, Io.XmlInput.SoilProfile1D[] inputSoilProfiles1D)
{
int profilesCount = dikeSoilProfiles.Count;
for (var i = 0; i < profilesCount; i++)
{
SoilProfile1D soilProfile1D = dikeSoilProfiles[i];
var inputSoilProfile1D = new Io.XmlInput.SoilProfile1D
{
Name = soilProfile1D.Name,
BottomLevel = soilProfile1D.BottomLevel,
Layers1D = new SoilProfile1DLayer1D[soilProfile1D.LayerCount]
};
AddLayers1D(soilProfile1D, inputSoilProfile1D);
inputSoilProfiles1D[i] = inputSoilProfile1D;
}
}
private static void AddLayers1D(SoilProfile1D soilProfile1D, Io.XmlInput.SoilProfile1D inputSoilProfile1D)
{
for (var i = 0; i < soilProfile1D.LayerCount; i++)
{
SoilLayer1D layer = soilProfile1D.Layers[i];
var inputLayer = new SoilProfile1DLayer1D
{
Name = layer.Name,
SoilName = layer.Soil.Name,
TopLevel = layer.TopLevel,
IsAquifer = layer.IsAquifer,
WaterpressureInterpolationModel = ConversionHelper.ConvertToInputWaterpressureInterpolationModel(
layer.WaterpressureInterpolationModel)
};
inputSoilProfile1D.Layers1D[i] = inputLayer;
}
}
private static void TransferSoilProfiles2D(IList dikeSoilProfiles2D,
Io.XmlInput.SoilProfile2D[] inputSoilProfiles2D)
{
int profilesCount = dikeSoilProfiles2D.Count;
for (var i = 0; i < profilesCount; i++)
{
SoilProfile2D soilProfile2D = dikeSoilProfiles2D[i];
var inputSoilProfile2D = new Io.XmlInput.SoilProfile2D
{
Name = soilProfile2D.Name,
Layers2D = new SoilProfile2DLayer2D[soilProfile2D.Surfaces.Count]
};
AddPreconsolidationStresses(soilProfile2D, inputSoilProfile2D);
AddLayers2D(soilProfile2D, inputSoilProfile2D);
inputSoilProfiles2D[i] = inputSoilProfile2D;
}
}
private static void AddPreconsolidationStresses(SoilProfile2D soilProfile2D, Io.XmlInput.SoilProfile2D inputSoilProfile2D)
{
if (soilProfile2D.PreconsolidationStresses != null)
{
int preconCount = soilProfile2D.PreconsolidationStresses.Count;
inputSoilProfile2D.PreconsolidationStresses = new SoilProfile2DPreconsolidationStress[preconCount];
for (var i = 0; i < preconCount; i++)
{
PreConsolidationStress precon = soilProfile2D.PreconsolidationStresses[i];
var inputPrecon = new SoilProfile2DPreconsolidationStress
{
Name = precon.Name,
StressValue = precon.StressValue,
X = precon.X,
Z = precon.Z
};
inputSoilProfile2D.PreconsolidationStresses[i] = inputPrecon;
}
}
}
private static void AddLayers2D(SoilProfile2D soilProfile2D, Io.XmlInput.SoilProfile2D inputSoilProfile2D)
{
if (soilProfile2D != null)
{
for (var i = 0; i < soilProfile2D.Surfaces.Count; i++)
{
SoilLayer2D layer = soilProfile2D.Surfaces[i];
var inputLayer = new SoilProfile2DLayer2D
{
SoilName = layer.Soil.Name,
IsAquifer = layer.IsAquifer,
WaterpressureInterpolationModel = ConversionHelper.ConvertToInputWaterpressureInterpolationModel(
layer.WaterpressureInterpolationModel),
Surface = new SoilProfile2DLayer2DSurface()
};
GeometryLoop loop = layer.GeometrySurface.OuterLoop;
inputLayer.Surface.OuterLoop = new SoilProfile2DLayer2DSurfaceOuterPoint[loop.Points.Count];
for (var j = 0; j < loop.Points.Count; j++)
{
var point = new SoilProfile2DLayer2DSurfaceOuterPoint
{
X = loop.Points[j].X,
Z = loop.Points[j].Z
};
inputLayer.Surface.OuterLoop[j] = point;
}
GeometryLoop innerloop = layer.GeometrySurface.InnerLoops.FirstOrDefault();
if (innerloop != null)
{
inputLayer.Surface.Innerloop = new SoilProfile2DLayer2DSurfaceInnerPoint[innerloop.Points.Count];
for (var j = 0; j < innerloop.Points.Count; j++)
{
var point = new SoilProfile2DLayer2DSurfaceInnerPoint
{
X = innerloop.Points[j].X,
Z = innerloop.Points[j].Z
};
inputLayer.Surface.Innerloop[j] = point;
}
}
inputSoilProfile2D.Layers2D[i] = inputLayer;
}
}
}
private static void TransferSegments(IList segments, Io.XmlInput.Segment[] inputSegments)
{
for (var i = 0; i < segments.Count; i++)
{
Segment segment = segments[i];
var inputSegment = new Io.XmlInput.Segment
{
Name = segment.Name
};
AddSoilProfileProbabilities(segment, inputSegment);
inputSegments[i] = inputSegment;
}
}
private static void AddSoilProfileProbabilities(Segment segment, Io.XmlInput.Segment inputSegment)
{
if (segment.SoilProfileProbabilities != null)
{
int probabilityCount = segment.SoilProfileProbabilities.Count;
inputSegment.SoilGeometryProbability = new SegmentSoilGeometryProbability[probabilityCount];
for (var i = 0; i < probabilityCount; i++)
{
SoilGeometryProbability soilGeometryProbability = segment.SoilProfileProbabilities[i];
var inputSoilGeometryProbability = new SegmentSoilGeometryProbability();
inputSoilGeometryProbability.Probability = soilGeometryProbability.Probability;
if (soilGeometryProbability.SegmentFailureMechanismType.HasValue)
{
inputSoilGeometryProbability.SegmentFailureMechanismType = ConversionHelper.ConvertToInputSegmentFailureMechanismSystemType(soilGeometryProbability.SegmentFailureMechanismType.Value);
inputSoilGeometryProbability.SegmentFailureMechanismTypeSpecified = true;
}
else
{
inputSoilGeometryProbability.SegmentFailureMechanismTypeSpecified = false;
}
inputSoilGeometryProbability.SoilProfileType = ConversionHelper.ConvertToInputSoilGeometryType(soilGeometryProbability.SoilProfileType);
switch (soilGeometryProbability.SoilProfileType)
{
case SoilProfileType.ProfileType1D:
{
inputSoilGeometryProbability.SoilProfileName = soilGeometryProbability.SoilProfile1DName;
break;
}
case SoilProfileType.ProfileType2D:
{
inputSoilGeometryProbability.SoilProfileName = soilGeometryProbability.SoilProfile2DName;
break;
}
}
inputSegment.SoilGeometryProbability[i] = inputSoilGeometryProbability;
}
}
}
}