// Copyright (C) Stichting Deltares 2017. 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 Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Io.XmlInput;
using Input = Deltares.DamEngine.Io.XmlInput.Input;
using Location = Deltares.DamEngine.Data.General.Location;
using Soil = Deltares.DamEngine.Io.XmlInput.Soil;
using SoilProfile1D = Deltares.DamEngine.Data.Geotechnics.SoilProfile1D;
namespace Deltares.DamEngine.Interface
{
public class FillXmlInputFromDam
{
///
/// Creates the input from Dam data.
///
/// The dam project data.
///
public static Input CreateInput(DamProjectData damProjectData)
{
Input input = new Input();
input.DamProjectType = ConversionHelper.ConvertToInputDamProjectType(damProjectData.DamProjectType);
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 Soil[dike.SoilList.Soils.Count];
TransferSoils(dike.SoilList.Soils, input.Soils);
input.SoilProfiles1D = new Io.XmlInput.SoilProfile1D[dike.SoilProfiles.Count];
TransferSoilProfiles1D(dike.SoilProfiles, input.SoilProfiles1D);
return input;
}
private static void TransferSoils(List soils, Soil[] inputSoils)
{
for (int i = 0; i < soils.Count; i++)
{
var soil = soils[i];
var inputSoil = new Soil();
inputSoil.Name = soil.Name;
inputSoil.BeddingAngleSpecified = !Double.IsNaN(soil.BeddingAngle);
inputSoil.BeddingAngle = soil.BeddingAngle;
inputSoil.DiameterD70Specified = !Double.IsNaN(soil.DiameterD70);
inputSoil.DiameterD70 = soil.DiameterD70;
inputSoil.DiameterD90Specified = !Double.IsNaN(soil.DiameterD70);
inputSoil.DiameterD90 = soil.DiameterD90;
inputSoil.PermeabKxSpecified = !Double.IsNaN(soil.DiameterD90);
inputSoil.PermeabKx = soil.PermeabKx;
inputSoil.WhitesConstantSpecified = !Double.IsNaN(soil.WhitesConstant);
inputSoil.WhitesConstant = soil.WhitesConstant;
inputSoils[i] = inputSoil;
}
}
private static void TransferSurfaceLines(IList dikeSurfaceLines, SurfaceLine[] inputSurfaceLines)
{
for (int i = 0; i < dikeSurfaceLines.Count; i++)
{
var surfaceLine = dikeSurfaceLines[i];
var inputSurfaceLine = new SurfaceLine();
inputSurfaceLine.Name = surfaceLine.Name;
inputSurfaceLine.Points = new SurfaceLinePoint[surfaceLine.CharacteristicPoints.Count];
for (int j = 0; j < surfaceLine.CharacteristicPoints.Count; j++)
{
var characteristicPoint = surfaceLine.CharacteristicPoints[j];
var inputPoint = new SurfaceLinePoint()
{
PointType = ConversionHelper.ConvertToInputPointType(characteristicPoint.CharacteristicPointType),
X = characteristicPoint.X,
Z = characteristicPoint.Z
};
inputSurfaceLine.Points[j] = inputPoint;
}
inputSurfaceLines[i] = inputSurfaceLine;
}
}
private static void TransferLocations(IList dikeLocations, Io.XmlInput.Location[] inputLocations)
{
int locationCount = dikeLocations.Count;
for (int i = 0; i < locationCount; i++)
{
var location = dikeLocations[i];
var inputLocation = new Io.XmlInput.Location();
var waternetOptions = new LocationWaternetOptions();
inputLocation.SurfaceLineName = location.SurfaceLine2.Name;
waternetOptions.PhreaticLineCreationMethod = ConversionHelper.ConvertToInputPhreaticLineCreationMethod(location.ModelParametersForPLLines.PLLineCreationMethod);
waternetOptions.IntrusionVerticalWaterPressure = ConversionHelper.ConvertToInputIntrusionVerticalWaterPressure(location.IntrusionVerticalWaterPressure ?? IntrusionVerticalWaterPressureType.Standard);
waternetOptions.PolderLevel = location.PolderLevel;
waternetOptions.DampingFactorPL3 = location.ModelParametersForPLLines.DampingFactorPL4;
waternetOptions.DampingFactorPL4 = location.ModelParametersForPLLines.DampingFactorPL3;
waternetOptions.PenetrationLength = location.ModelParametersForPLLines.PenetrationLength;
waternetOptions.Pl1BelowCrestMiddleSpecified = location.PlLineOffsetBelowDikeCrestMiddle.HasValue;
waternetOptions.Pl1BelowCrestMiddle = location.PlLineOffsetBelowDikeCrestMiddle ?? 0.0;
waternetOptions.Pl1FactorBelowShoulderCrestSpecified = location.UsePlLineOffsetFactorBelowShoulderCrest ?? false;
waternetOptions.Pl1FactorBelowShoulderCrest = location.PlLineOffsetFactorBelowShoulderCrest ?? 0.0;
waternetOptions.DryPl1BelowCrestMiddleSpecified = location.PlLineOffsetDryBelowDikeCrestMiddle.HasValue;
waternetOptions.DryPl1BelowCrestMiddle = location.PlLineOffsetDryBelowDikeCrestMiddle ?? 0.0;
waternetOptions.DryPl1FactorBelowShoulderCrestSpecified = location.UsePlLineOffsetDryFactorBelowShoulderCrest ?? false;
waternetOptions.DryPl1FactorBelowShoulderCrest = location.PlLineOffsetDryFactorBelowShoulderCrest ?? 0.0;
waternetOptions.HeadPl2Specified = location.HeadPl2.HasValue;
waternetOptions.HeadPl2 = location.HeadPl2 ?? 0.0;
waternetOptions.HeadPl3Specified = location.HeadPl3.HasValue;
waternetOptions.HeadPl3 = location.HeadPl3 ?? 0.0;
waternetOptions.HeadPl4Specified = location.HeadPl4.HasValue;
waternetOptions.HeadPl4 = location.HeadPl4 ?? 0.0;
waternetOptions.SlopeDampingFactor = location.SlopeDampingPiezometricHeightPolderSide;
waternetOptions.Pl1BelowCrestRiverside = location.PlLineOffsetBelowDikeTopAtRiver;
waternetOptions.Pl1BelowCrestPolderside = location.PlLineOffsetBelowDikeTopAtPolder;
waternetOptions.Pl1BelowShoulderCrestPolderside = location.PlLineOffsetBelowShoulderBaseInside;
waternetOptions.Pl1BelowToeDikePolderside = location.PlLineOffsetBelowDikeToeAtPolder;
inputLocation.WaternetOptions = waternetOptions;
inputLocations[i] = inputLocation;
}
}
private static void TransferSoilProfiles1D(IList dikeSoilProfiles,
Io.XmlInput.SoilProfile1D[] inputSoilProfiles1D)
{
var profilesCount = dikeSoilProfiles.Count;
for (int i = 0; i < profilesCount; i++)
{
var soilProfile1D = dikeSoilProfiles[i];
var inputSoilProfile1D = new Io.XmlInput.SoilProfile1D
{
Name = soilProfile1D.Name,
BottomLevel = soilProfile1D.BottomLevel,
Layers = new SoilProfile1DLayer[soilProfile1D.LayerCount]
};
AddLayers(soilProfile1D, inputSoilProfile1D);
}
}
private static void AddLayers(SoilProfile1D soilProfile1D, Io.XmlInput.SoilProfile1D inputSoilProfile1D)
{
for (int i = 0; i < soilProfile1D.LayerCount; i++)
{
var layer = soilProfile1D.Layers[i];
var inputLayer = new SoilProfile1DLayer
{
Name = layer.Name,
SoilName = layer.Soil.Name,
TopLevel = layer.TopLevel,
IsAquifer = layer.IsAquifer,
WaterpressureInterpolationModel = ConversionHelper.ConvertToInputWaterpressureInterpolationModel(
layer.WaterpressureInterpolationModel)
};
}
}
}
}