// Copyright (C) Stichting Deltares 2020. All rights reserved. // // This file is part of the Layer On Slope Tool. // // The Layer On Slope Tool 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.Collections.Generic; using System.IO; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; namespace Deltares.LayerOnSlopeTool.Io.Tests { [TestFixture] public class IoDamMStabDocSeriliazerTests { private const string TestFileFolder = @"TestFiles\"; [Test] public void GivenFilledDamMStabDocWhenSerializingDeserializingThenObjectsAreEqual() { string filename = Path.Combine(TestFileFolder, "MStabDamDocExample.xml"); // Given Filled DamMStabDoc IoMStabDamDoc expectedMStabDamDoc = CreateMStabDamDocExample(); // When Serializing/Deserializing IoDamMStabDocSerializer damMStabDocSerializer = new IoDamMStabDocSerializer(); damMStabDocSerializer.Save(filename, expectedMStabDamDoc); IoMStabDamDoc actualMStabDamDoc = damMStabDocSerializer.Load(filename); // Then Objects Are Equal CompareMStabDamDoc(actualMStabDamDoc, expectedMStabDamDoc); } private void CompareMStabDamDoc(IoMStabDamDoc actual, IoMStabDamDoc 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:" + result.DifferencesString); } private IoMStabDamDoc CreateMStabDamDocExample() { const double xLeftBoundary = 1.0; const double xRightBoundary = 15.00; const double yDeep = -100.0; var ioMStabDamDoc = new IoMStabDamDoc(); ioMStabDamDoc.MStabInput.MStabFileName = "MStabFileName"; ioMStabDamDoc.MStabInput.SoilDbName = "SoilDbName"; FillGeometryCreationOptions(ioMStabDamDoc.MStabInput.GeometryCreationOptions); FillModel(ioMStabDamDoc.MStabInput.Model); FillSurfaceLine(ioMStabDamDoc.MStabInput.SurfaceLine, xLeftBoundary, xRightBoundary); FillCharacteristicPoints(ioMStabDamDoc.MStabInput.CharacteristicPoints, xLeftBoundary, xRightBoundary); FillPlLines(ioMStabDamDoc.MStabInput.ExternalPlLines, xRightBoundary, xLeftBoundary, yDeep); FillCalculationOptions(ioMStabDamDoc.MStabInput.CalculationOptions); FillTrafficLoad(ioMStabDamDoc.MStabInput.TrafficLoad); FillHoriontalBalanceArea(ioMStabDamDoc.MStabInput.HorizontalBalanceArea); FillSlipCircleDefinition(ioMStabDamDoc.MStabInput.SlipCircleDefinition); return ioMStabDamDoc; } private void FillSlipCircleDefinition(IoSlipCircleDefinition slipCircleDefinition) { slipCircleDefinition.BishopTangentLinesDefinition = TangentLinesDefinitionType.Specified; slipCircleDefinition.UpliftVanTangentLinesDefinition = TangentLinesDefinitionType.Specified; slipCircleDefinition.GridSizeDetermination = GridSizeDeterminationType.Specified; } private void FillHoriontalBalanceArea(IoHorizontalBalanceArea horizontalBalanceArea) { horizontalBalanceArea.XLeft = 4.0; horizontalBalanceArea.XRight = 6.0; horizontalBalanceArea.YTop = 3.5; horizontalBalanceArea.YBottom = 2.5; horizontalBalanceArea.PlaneCount = 8; } private void FillTrafficLoad(IoTrafficLoad trafficLoad) { trafficLoad.XCoordinateAtRiver = 5.2; trafficLoad.XCoordinateAtPolder = 5.7; trafficLoad.DegreeOfConsolidationSpecified = true; trafficLoad.DegreeOfConsolidation = 10.0; trafficLoad.Load = 5.0; } private void FillCalculationOptions(IoCalculationOptions calculationOptions) { calculationOptions.MinimalCircleDepth = 0.75; calculationOptions.ZonesType = ZonesType.ForbiddenZone; } private static void FillPlLines(List plLines, double xRightBoundary, double xLeftBoundary, double yDeep) { var pl1 = new IoPlLine(); pl1.IsPhreatic = true; pl1.BoundaryLayer = 1; pl1.Points.Add(new IoGeometryPoint() { X = xLeftBoundary, Y = -1.0 }); pl1.Points.Add(new IoGeometryPoint() { X = 0.5 * (xRightBoundary + xLeftBoundary), Y = -2.0 }); pl1.Points.Add(new IoGeometryPoint() { X = xRightBoundary, Y = -1.5 }); plLines.Add(pl1); var pl2 = new IoPlLine(); pl2.IsPhreatic = false; pl2.BoundaryLayer = 2; pl2.Points.Add(new IoGeometryPoint() { X = xLeftBoundary, Y = yDeep }); pl1.Points.Add(new IoGeometryPoint() { X = xRightBoundary, Y = yDeep }); plLines.Add(pl2); var pl3 = new IoPlLine(); pl3.IsPhreatic = false; pl3.BoundaryLayer = 1; pl3.Points.Add(new IoGeometryPoint() { X = xLeftBoundary, Y = yDeep }); pl1.Points.Add(new IoGeometryPoint() { X = xRightBoundary, Y = yDeep }); plLines.Add(pl3); var pl4 = new IoPlLine(); pl4.IsPhreatic = false; pl4.BoundaryLayer = 0; plLines.Add(pl4); } private static void FillCharacteristicPoints(List characteristicPoints, double xLeftBoundary, double xRightBoundary) { characteristicPoints.Add(new IoCharacteristicPoint() { X = xLeftBoundary, Y = 1.5, CharacteristicPointType = CharacteristicPointType.SurfaceLevelOutside }); characteristicPoints.Add(new IoCharacteristicPoint() { X = 3.0, Y = 1.5, CharacteristicPointType = CharacteristicPointType.DikeToeAtRiver }); characteristicPoints.Add(new IoCharacteristicPoint() { X = 5.0, Y = 2.5, CharacteristicPointType = CharacteristicPointType.DikeTopAtRiver }); characteristicPoints.Add(new IoCharacteristicPoint() { X = 7.0, Y = 2.5, CharacteristicPointType = CharacteristicPointType.DikeTopAtPolder }); characteristicPoints.Add(new IoCharacteristicPoint() { X = 10.0, Y = 0.5, CharacteristicPointType = CharacteristicPointType.DikeToeAtPolder }); characteristicPoints.Add(new IoCharacteristicPoint() { X = xRightBoundary, Y = 0.5, CharacteristicPointType = CharacteristicPointType.SurfaceLevelInside }); } private static void FillSurfaceLine(List surfaceLine, double xLeftBoundary, double xRightBoundary) { surfaceLine.Add(new IoGeometryPoint() { X = xLeftBoundary, Y = 1.5 }); surfaceLine.Add(new IoGeometryPoint() { X = 2.0, Y = 1.5 }); surfaceLine.Add(new IoGeometryPoint() { X = 3.0, Y = 1.5 }); surfaceLine.Add(new IoGeometryPoint() { X = 5.0, Y = 2.5 }); surfaceLine.Add(new IoGeometryPoint() { X = 6.0, Y = 2.5 }); surfaceLine.Add(new IoGeometryPoint() { X = 7.0, Y = 2.5 }); surfaceLine.Add(new IoGeometryPoint() { X = 10.0, Y = 0.5 }); surfaceLine.Add(new IoGeometryPoint() { X = xRightBoundary, Y = 0.5 }); } private static void FillModel(IoModel model) { model.CalculationModel = ModelType.UpliftVan; model.GridPosition = GridPositionType.Right; model.Probabilistic = false; model.SearchMethod = SearchMethodType.Grid; model.ShearStrength = ShearStrengthType.CPhi; } private static void FillGeometryCreationOptions(IoGeometryCreationOptions geometryCreationOptions) { geometryCreationOptions.MaterialForDike = "DikeMaterial"; geometryCreationOptions.SoilGeometry2DFilename = "Geometry2DFilename"; geometryCreationOptions.SoilGeometryType = SoilGeometryType.SoilGeometry2D; geometryCreationOptions.XOffsetSoilGeometry2DOrigin = 1.1; geometryCreationOptions.PenetrationLength = 0.8; geometryCreationOptions.PlLineAssignment = PlLineAssignment.ExpertKnowledge; } } }