// 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 Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; using Soil = Deltares.DamEngine.Data.Geotechnics.Soil; namespace Deltares.DamEngine.Interface.Tests { [TestFixture] public class FillDamFromXmlInputTests { [Test] public void CanWriteAndReadDamProjectDataToXml() { const string inputFilename = "InputFile.xml"; DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Input input = FillXmlInputFromDam.CreateInput(expectedDamProjectData); DamXmlSerialization.SaveInputAsXmlFile(inputFilename, input); input = DamXmlSerialization.LoadInputFromXmlFile(inputFilename); DamProjectData actualDamProjectData = FillDamFromXmlInput.CreateDamProjectData(input); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } [Test] public void CanWriteAndReadDamProjectDataToXmlString() { string xmlString; DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Input input = FillXmlInputFromDam.CreateInput(expectedDamProjectData); xmlString = DamXmlSerialization.SaveInputAsXmlString(input); input = DamXmlSerialization.LoadInputFromXmlString(xmlString); DamProjectData actualDamProjectData = FillDamFromXmlInput.CreateDamProjectData(input); CompareDamProjectData(actualDamProjectData, expectedDamProjectData); } private void AddPointToSurfaceLine(SurfaceLine2 surfaceLine, double xCoordinate, double zCoordinate, CharacteristicPointType characteristicPointType) { var geometryPoint = new GeometryPoint() { X = xCoordinate, Y = 0.0, Z = zCoordinate, }; surfaceLine.AddCharacteristicPoint(geometryPoint, characteristicPointType); } private DamProjectData CreateExampleDamProjectData() { var damProjectData = new DamProjectData(); damProjectData.DamProjectType = DamProjectType.Design; damProjectData.Dike = new Dike(); Dike dike = damProjectData.Dike; FillSurfaceLines(dike); FillSoils(dike); FillLocations(dike); return damProjectData; } private void FillSoils(Dike dike) { const int soilCount = 3; dike.SoilList = new SoilList(); for (int i = 0; i < soilCount; i++) { Soil soil = new Soil() {Name = String.Format("Soil {0}", i)}; //soil.SoilType = SoilType.Loam; //soil.AbovePhreaticLevel = 10 + 0.1 * i; //soil.BelowPhreaticLevel = 10 + 0.1 * i; //soil.DryUnitWeight = 10 + 0.1 * i; //soil.ShearStrengthModel = ShearStrengthModel.CuMeasured; //soil.Cohesion = 10 + 0.1 * i; //soil.CuBottom = 11 + 0.1 * i; //soil.CuTop = 12 + 0.1 * i; //soil.DilatancyType = DilatancyType.Zero; //soil.FrictionAngle = 13 + 0.1 * i; //soil.Ocr = 14 + 0.1 * i; //soil.PoP = 15 + 0.1 * i; //soil.RatioCuPc = 16 + 0.1 * i; //soil.StrengthIncreaseExponent = 17 + 0.1 * i; //soil.UsePop = true; soil.BeddingAngle = 18 + 0.1 * i; soil.DiameterD70 = 19 + 0.1 * i; soil.DiameterD90 = 20 + 0.1 * i; soil.PermeabKx = 21 + 0.1 * i; soil.WhitesConstant = 22 + 0.1 * i; dike.SoilList.Add(soil); } } private void FillSurfaceLines(Dike dike) { const int surfaceLineCount = 3; for (int i = 0; i < surfaceLineCount; i++) { var surfaceLine = new SurfaceLine2(); surfaceLine.Name = String.Format("SurfaceLine {0}", i); surfaceLine.CharacteristicPoints.Geometry = surfaceLine.Geometry; AddPointsToSurfaceLines(surfaceLine); dike.SurfaceLines2.Add(surfaceLine); } } private void AddPointsToSurfaceLines(SurfaceLine2 surfaceLine) { AddPointToSurfaceLine(surfaceLine, 0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); AddPointToSurfaceLine(surfaceLine, 2.0, 0.5, CharacteristicPointType.None); AddPointToSurfaceLine(surfaceLine, 4.0, 0.0, CharacteristicPointType.DikeToeAtRiver); AddPointToSurfaceLine(surfaceLine, 9.0, 5.0, CharacteristicPointType.DikeTopAtRiver); AddPointToSurfaceLine(surfaceLine, 10.0, 5.2, CharacteristicPointType.None); AddPointToSurfaceLine(surfaceLine, 13.0, 5.4, CharacteristicPointType.DikeTopAtPolder); AddPointToSurfaceLine(surfaceLine, 18.0, 1.0, CharacteristicPointType.DikeToeAtPolder); AddPointToSurfaceLine(surfaceLine, 24.0, 1.0, CharacteristicPointType.SurfaceLevelInside); } private static void FillLocations(Dike dike) { const int locationCount = 3; for (int i = 0; i < locationCount; i++) { var location = new Data.General.Location(); location.ModelParametersForPLLines.PLLineCreationMethod = (PLLineCreationMethod) i; location.IntrusionVerticalWaterPressure = (IntrusionVerticalWaterPressureType) i; location.PolderLevel = 1.0 * i + 0.11; location.ModelParametersForPLLines.DampingFactorPL4 = 1.0 * i + 0.12; location.ModelParametersForPLLines.DampingFactorPL3 = 1.0 * i + 0.13; location.ModelParametersForPLLines.PenetrationLength = 1.0 * i + 0.14; location.PlLineOffsetBelowDikeCrestMiddle = 1.0 * i + 0.15; location.UsePlLineOffsetFactorBelowShoulderCrest = true; location.PlLineOffsetFactorBelowShoulderCrest = 1.0 * i + 0.16; location.PlLineOffsetDryBelowDikeCrestMiddle = 1.0 * i + 0.17; location.UsePlLineOffsetDryFactorBelowShoulderCrest = true; location.PlLineOffsetDryFactorBelowShoulderCrest = 1.0 * i + 0.18; location.SlopeDampingPiezometricHeightPolderSide = 1.0 * i + 0.19; location.PlLineOffsetBelowDikeTopAtRiver = 1.0 * i + 0.20; location.PlLineOffsetBelowDikeTopAtPolder = 1.0 * i + 0.21; location.PlLineOffsetBelowShoulderBaseInside = 1.0 * i + 0.22; location.PlLineOffsetBelowDikeToeAtPolder = 1.0 * i + 0.23; location.HeadPl2 = 1.0 * i + 0.24; location.HeadPl3 = 1.0 * i + 0.25; location.HeadPl4 = 1.0 * i + 0.21; location.SurfaceLine2 = dike.SurfaceLines2[i]; dike.Locations.Add(location); } } private void CompareDamProjectData(DamProjectData actual, DamProjectData expected) { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; var result = compare.Compare(expected, actual); Assert.AreEqual(0, result.Differences.Count, "Differences found read/write Input object"); } } }