Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/ConversionHelperTests.cs =================================================================== diff -u -r2002 -r2017 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/ConversionHelperTests.cs (.../ConversionHelperTests.cs) (revision 2002) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/ConversionHelperTests.cs (.../ConversionHelperTests.cs) (revision 2017) @@ -127,7 +127,7 @@ BelowPhreaticLevel = 1.02, Cohesion = 1.03, FrictionAngle = 1.04, - Dilatancy = -1.045, // -Phi (FrictionAngle) + Dilatancy = -1.04, // -Phi (FrictionAngle) RRatio = 1.05, RatioCuPc = 1.06, RheologicalCoefficient = 1.07, Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIoTests.cs =================================================================== diff -u -r2009 -r2017 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIoTests.cs (.../MacroStabilityIoTests.cs) (revision 2009) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroStabilityIoTests.cs (.../MacroStabilityIoTests.cs) (revision 2017) @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using NUnit.Framework; using Deltares.MacroStability.Kernel; using Deltares.DamEngine.Data.General; @@ -29,8 +30,12 @@ using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.TestHelpers.Factories; using Deltares.MacroStability.Data; +using Deltares.MacroStability.Geometry; using Deltares.MacroStability.Standard; using KellermanSoftware.CompareNetObjects; +using Soil = Deltares.MacroStability.Geometry.Soil; +using SoilProfile2D = Deltares.DamEngine.Data.Geotechnics.SoilProfile2D; +using SurfaceLine2 = Deltares.DamEngine.Data.Geotechnics.SurfaceLine2; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityCommon { @@ -59,18 +64,20 @@ } [Test] - [Category(Categories.WorkInProgress)] + [Category(Categories.WorkInProgress)] // The actual code has to be implemented public void GivenDamEngineDataModelWhenSerializingAndDeserializingTheDataModelsAreEqual() { // Given DamEngine data (DamProjectData) DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); Location expectedLocation = expectedDamProjectData.Dike.Locations[0]; + SoilList expectedSoilList = expectedDamProjectData.Dike.SoilList; SoilProfile2D expectedSoilProfile2D = expectedLocation.Segment.SoilProfileProbabilities[0].SoilProfile2D; SurfaceLine2 expectedSurfaceLine2D = expectedLocation.SurfaceLine; FailureMechanismParametersMStab expectedParametersMStab = expectedDamProjectData.DamProjectCalculationSpecification.CurrentSpecification.FailureMechanismParametersMStab; FillWtiKernelData fillWtiKernelData = new FillWtiKernelData() { + SoilList = expectedSoilList, FailureMechanismParametersMStab = expectedParametersMStab, Location = expectedLocation, SoilProfile2D = expectedSoilProfile2D, @@ -89,10 +96,13 @@ // Then the data models are equal var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; - var result = compare.Compare(expectedLocation, fillDamEngineFromWti.Location); - Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel Location"); + ComparisonResult result; result = compare.Compare(expectedSoilProfile2D, fillDamEngineFromWti.SoilProfile2D); Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SoilProfile2D"); + result = compare.Compare(expectedSoilList, fillDamEngineFromWti.SoilList); + Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SoilList"); + result = compare.Compare(expectedLocation, fillDamEngineFromWti.Location); + Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel Location"); result = compare.Compare(expectedSurfaceLine2D, fillDamEngineFromWti.SurfaceLine2); Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SurfaceLine2"); result = compare.Compare(expectedParametersMStab, fillDamEngineFromWti.FailureMechanismParametersMStab); @@ -102,7 +112,6 @@ [TestCase("Benchmark 1-01b.wti")] [TestCase("Benchmark 2-04a.wti")] - //[Category(Categories.WorkInProgress)] public void GivenWtiFileWhenFillingToDamEngineDataAndWritingBackToKernelDataThenTheKernelModelsAreEqual(string fileNameIn) { // Given Wti file @@ -117,6 +126,7 @@ // And writing back to kernel data FillWtiKernelData fillWtiKernelData = new FillWtiKernelData() { + SoilList = fillDamEngineFromWti.SoilList, FailureMechanismParametersMStab = fillDamEngineFromWti.FailureMechanismParametersMStab, Location = fillDamEngineFromWti.Location, SoilProfile2D = fillDamEngineFromWti.SoilProfile2D, @@ -130,19 +140,47 @@ // Then the kernel models are equal CompareStabilityModel(expectedKernelModel.StabilityModel, actualKernelModel.StabilityModel); - return; + CompareSoilModel(expectedKernelModel.StabilityModel.SoilModel, actualKernelModel.StabilityModel.SoilModel); + CompareSoilProfile2D(expectedKernelModel.StabilityModel.SoilProfile, actualKernelModel.StabilityModel.SoilProfile); + } - //Enable asserts when code is implemented + private void CompareSoilProfile2D(MacroStability.Geometry.SoilProfile2D expectedSoilProfile, MacroStability.Geometry.SoilProfile2D actualSoilProfile) + { var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; compare.Config.MembersToIgnore = new List { + "StrengthIncreaseExponent", + "RRatio", + "RheologicalCoefficient", + "BondStressCurve", + "UseSoilType" }; - var result = compare.Compare(expectedKernelModel.StabilityModel.SoilModel, actualKernelModel.StabilityModel.SoilModel); - Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SoilModel"); - result = compare.Compare(expectedKernelModel.StabilityModel.SoilProfile, actualKernelModel.StabilityModel.SoilProfile); - Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SoilProfile"); + var result = compare.Compare(expectedSoilProfile, actualSoilProfile); + Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SoilProfile2D"); } + + private void CompareSoilModel(SoilModel expectedSoilModel, SoilModel actualSoilModel) + { + Assert.AreEqual(expectedSoilModel.Soils.Count, actualSoilModel.Soils.Count, "Soil Count does not match"); + foreach (Soil expectedSoil in expectedSoilModel.Soils) + { + var actualSoil = actualSoilModel.Soils.First(soil => soil.Name.Equals(expectedSoil.Name)); + Assert.IsNotNull(actualSoil, string.Format("Soil {0} not found", expectedSoil.Name)); + var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; + compare.Config.MembersToIgnore = new List + { + "StrengthIncreaseExponent", + "RRatio", + "RheologicalCoefficient", + "BondStressCurve", + "UseSoilType" + }; + var result = compare.Compare(expectedSoil, actualSoil); + Assert.AreEqual(0, result.Differences.Count, "Differences found read/write kernel SoilProfile"); + } + } + private void CompareStabilityModel(StabilityModel expectedStabilityModel, StabilityModel actualStabilityModel) { Assert.AreEqual(expectedStabilityModel.SearchAlgorithm, actualStabilityModel.SearchAlgorithm); Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillDamEngineFromWti.cs =================================================================== diff -u -r2003 -r2017 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillDamEngineFromWti.cs (.../FillDamEngineFromWti.cs) (revision 2003) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillDamEngineFromWti.cs (.../FillDamEngineFromWti.cs) (revision 2017) @@ -19,36 +19,65 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System.Collections.Generic; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.Geotechnics; using Deltares.MacroStability.Data; using Deltares.MacroStability.Kernel; +using Soil = Deltares.MacroStability.Geometry.Soil; +using Deltares.MacroStability.Geometry; namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo { + /// Fill DamEngine data objects from the kernel data model public class FillDamEngineFromWti { + /// Gets or sets the SoilList DamEngine object + /// The soil list. + public SoilList SoilList { get; set; } + /// Gets or sets the location DamEngine object. + /// The location. public Location Location { get; set; } - public SoilProfile2D SoilProfile2D { get; set; } - public SurfaceLine2 SurfaceLine2 { get; set; } + /// Gets or sets the SoilProfile2D DamEngine object. + /// The soil profile2 d. + public Data.Geotechnics.SoilProfile2D SoilProfile2D { get; set; } + /// Gets or sets the SurfaceLine2 DamEngine object. + /// The surface line2. + public Data.Geotechnics.SurfaceLine2 SurfaceLine2 { get; set; } + /// Gets or sets the failure mechanism parameters m stab. + /// The failure mechanism parameters for macrostability DamEngine object. public FailureMechanismParametersMStab FailureMechanismParametersMStab { get; set; } + + private Dictionary dictSoils = new Dictionary(); /// Creates the dam project data from the kernel model. /// The kernel model. /// The DamProjectData object filled with Wti data public void FillDamProjectDataFromKernelModel(KernelModel kernelModel) { + SoilList = new SoilList(); Location = new Location(); - SoilProfile2D = new SoilProfile2D(); - SurfaceLine2 = new SurfaceLine2(); + SoilProfile2D = new Data.Geotechnics.SoilProfile2D(); + SurfaceLine2 = new Data.Geotechnics.SurfaceLine2(); FailureMechanismParametersMStab = new FailureMechanismParametersMStab(); TransferWtiStabilityModel(kernelModel.StabilityModel, FailureMechanismParametersMStab); + TransferSoils(kernelModel.StabilityModel.Soils); + TransferSoilProfile2D(kernelModel.StabilityModel.SoilProfile); -// TransferLocation(kernelModel, Location); -// TransferSoilProfile2D(kernelModel, SoilProfile2D); -// TransferSurfaceLine2(kernelModel, SurfaceLine2); -// TransferParametersMStab(kernelModel, FailureMechanismParametersMStab); + // TransferLocation(kernelModel, Location); + // TransferSurfaceLine2(kernelModel, SurfaceLine2); + // TransferParametersMStab(kernelModel, FailureMechanismParametersMStab); } + private void TransferSoils(IList stabilityModelSoils) + { + foreach (Soil kernelSoil in stabilityModelSoils) + { + var damSoil = ConversionHelper.ConvertToDamSoil(kernelSoil); + dictSoils.Add(kernelSoil.Name, damSoil); + SoilList.Add(damSoil); + } + } + private void TransferWtiStabilityModel(StabilityModel kernelModelStabilityModel, FailureMechanismParametersMStab failureMechanismParametersMStab) { // kernelModelStabilityModel.MoveGrid is not in DamEngine datamodel @@ -57,41 +86,118 @@ ConversionHelper.ConvertToDamSearchMethod(kernelModelStabilityModel.SearchAlgorithm); failureMechanismParametersMStab.MStabParameters.Model = ConversionHelper.ConvertToMStabModelType(kernelModelStabilityModel.ModelOption); - failureMechanismParametersMStab.MStabParameters.GridPosition = + failureMechanismParametersMStab.MStabParameters.GridPosition = ConversionHelper.ConvertToMStabGridPosition(kernelModelStabilityModel.GridOrientation); } - /// Transfers the parameters m stab. - /// The kernel model. - /// The MStab parameters. - /// private void TransferParametersMStab(KernelModel kernelModel, FailureMechanismParametersMStab failureMechanismParametersMStab) { throw new System.NotImplementedException(); } - /// Transfers the surface line2. - /// The kernel model. - /// The SurfaceLine2. - /// - private void TransferSurfaceLine2(KernelModel kernelModel, SurfaceLine2 surfaceLine2) + private void TransferSurfaceLine2() { throw new System.NotImplementedException(); } - /// Transfers the soil profile2 d. - /// The kernel model. - /// The SoilProfile2D. - /// - private void TransferSoilProfile2D(KernelModel kernelModel, SoilProfile2D soilProfile2D) + private void TransferSoilProfile2D(MacroStability.Geometry.SoilProfile2D kernelsoilProfile2D) { - throw new System.NotImplementedException(); + Dictionary dictPoints = new Dictionary(); + Dictionary dictCurves = new Dictionary(); + Dictionary dictLoops = new Dictionary(); + Dictionary dictSurfaces = new Dictionary(); + // Add points + foreach (var kernelPoint in kernelsoilProfile2D.Geometry.Points) + { + Data.Geometry.Point2D damPoint; + if (dictPoints.ContainsKey(kernelPoint)) + { + damPoint = dictPoints[kernelPoint]; + } + else + { + damPoint = new Data.Geometry.Point2D() { X = kernelPoint.X, Z = kernelPoint.Z }; + dictPoints.Add(kernelPoint, damPoint); + } + SoilProfile2D.Geometry.Points.Add(damPoint); + } + + // Add curves + foreach (var kernelCurve in kernelsoilProfile2D.Geometry.Curves) + { + Data.Geometry.GeometryCurve damCurve; + if (dictCurves.ContainsKey(kernelCurve)) + { + damCurve = dictCurves[kernelCurve]; + } + else + { + var kernelHeadPoint = kernelCurve.HeadPoint; + var kernelEndPoint = kernelCurve.EndPoint; + var damHeadPoint = dictPoints[kernelHeadPoint]; + var damEndPoint = dictPoints[kernelEndPoint]; + damCurve = new Data.Geometry.GeometryCurve() { HeadPoint = damHeadPoint, EndPoint = damEndPoint }; + dictCurves.Add(kernelCurve, damCurve); + } + SoilProfile2D.Geometry.Curves.Add(damCurve); + } + + // Add loops + foreach (var kernelLoop in kernelsoilProfile2D.Geometry.Loops) + { + Data.Geometry.GeometryLoop damLoop; + if (dictLoops.ContainsKey(kernelLoop)) + { + damLoop = dictLoops[kernelLoop]; + } + else + { + damLoop = new Data.Geometry.GeometryLoop() { Name = kernelLoop.Name }; + foreach (var damCurve in kernelLoop.CurveList) + { + damLoop.CurveList.Add(dictCurves[damCurve]); + } + + dictLoops.Add(kernelLoop, damLoop); + } + SoilProfile2D.Geometry.Loops.Add(damLoop); + } + + // Add surfaces + foreach (var kernelSurface in kernelsoilProfile2D.Geometry.Surfaces) + { + Data.Geometry.GeometrySurface damSurface; + if (dictSurfaces.ContainsKey(kernelSurface)) + { + damSurface = dictSurfaces[kernelSurface]; + } + else + { + damSurface = new Data.Geometry.GeometrySurface() { Name = kernelSurface.Name }; + damSurface.OuterLoop = dictLoops[kernelSurface.OuterLoop]; + foreach (var damInnerLoop in kernelSurface.InnerLoops) + { + damSurface.InnerLoops.Add(dictLoops[damInnerLoop]); + } + + dictSurfaces.Add(kernelSurface, damSurface); + } + + SoilProfile2D.Geometry.Surfaces.Add(damSurface); + } + + // Add soil surfaces + foreach (var kernelSoilLayer2D in kernelsoilProfile2D.Surfaces) + { + Data.Geotechnics.SoilLayer2D damSoilLayer2D = new Data.Geotechnics.SoilLayer2D(); + damSoilLayer2D.GeometrySurface = dictSurfaces[kernelSoilLayer2D.GeometrySurface]; + damSoilLayer2D.Soil = dictSoils[kernelSoilLayer2D.Soil.Name]; + damSoilLayer2D.IsAquifer = kernelSoilLayer2D.IsAquifer; + damSoilLayer2D.WaterpressureInterpolationModel = ConversionHelper.ConvertToDamWaterpressureInterpolationModel(kernelSoilLayer2D.WaterpressureInterpolationModel); + SoilProfile2D.Surfaces.Add(damSoilLayer2D); + } } - /// Transfers the location. - /// The kernel model. - /// The location. - /// private void TransferLocation(KernelModel kernelModel, Location location) { throw new System.NotImplementedException(); Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillWtiKernelData.cs =================================================================== diff -u -r2009 -r2017 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillWtiKernelData.cs (.../FillWtiKernelData.cs) (revision 2009) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/FillWtiKernelData.cs (.../FillWtiKernelData.cs) (revision 2017) @@ -21,39 +21,54 @@ using System.Collections.Generic; using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.Geotechnics; using Deltares.MacroStability.Data; using Deltares.MacroStability.Geometry; using Deltares.MacroStability.Kernel; using Deltares.MacroStability.Preprocessing; using Location = Deltares.MacroStability.WaternetCreator.Location; using Soil = Deltares.MacroStability.Geometry.Soil; using SoilLayer2D = Deltares.DamEngine.Data.Geotechnics.SoilLayer2D; +using SoilProfile2D = Deltares.MacroStability.Geometry.SoilProfile2D; +using SurfaceLine2 = Deltares.MacroStability.Geometry.SurfaceLine2; namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo { + /// Fill the kernel data model from DamEngine data objects public class FillWtiKernelData { + /// Gets or sets the SoilList DamEngine object + /// The soil list. + public SoilList SoilList { get; set; } + /// Gets or sets the location DamEngine object. + /// The location. public Data.General.Location Location { get; set; } + /// Gets or sets the SoilProfile2D DamEngine object. + /// The soil profile2 d. public Data.Geotechnics.SoilProfile2D SoilProfile2D { get; set; } + /// Gets or sets the SurfaceLine2 DamEngine object. + /// The surface line2. public Data.Geotechnics.SurfaceLine2 SurfaceLine2 { get; set; } + /// Gets or sets the failure mechanism parameters m stab. + /// The failure mechanism parameters for macrostability DamEngine object. public FailureMechanismParametersMStab FailureMechanismParametersMStab { get; set; } + private Dictionary dictSoils = new Dictionary(); private Dictionary dictPoints = new Dictionary(); private Dictionary dictCurves = new Dictionary(); private Dictionary dictLoops = new Dictionary(); private Dictionary dictSurfaces = new Dictionary(); /// Creates the kernel model from dam project data. - /// The DamProjectData object filled with Wti data - /// The KernelModel filled with the Dam Project Data + /// The KernelModel filled with the Dam Project Data public KernelModel CreateKernelModel() { KernelModel kernelModel = new KernelModel(); kernelModel.StabilityModel = new StabilityModel(); kernelModel.PreprocessingModel = new PreprocessingModel(); TransferWtiStabilityModel(FailureMechanismParametersMStab, kernelModel.StabilityModel); - TransferSoils(SoilProfile2D, kernelModel.StabilityModel.SoilModel.Soils); - kernelModel.StabilityModel.SoilProfile = new MacroStability.Geometry.SoilProfile2D(); + TransferSoils(SoilList, SoilProfile2D, kernelModel.StabilityModel.SoilModel.Soils); + kernelModel.StabilityModel.SoilProfile = new SoilProfile2D(); TransferSoilProfile(SoilProfile2D, kernelModel.StabilityModel.SoilProfile); kernelModel.PreprocessingModel.LastStage.SurfaceLine = new SurfaceLine2(); TransferSurfaceLine(SurfaceLine2, kernelModel.PreprocessingModel.LastStage.SurfaceLine); // TODO @@ -108,8 +123,8 @@ var damHeadPoint = damCurve.HeadPoint; var damEndPoint = damCurve.EndPoint; var kernelHeadPoint = dictPoints[damHeadPoint]; - var kernelendPoint = dictPoints[damEndPoint]; - kernelCurve = new GeometryCurve() {HeadPoint = kernelHeadPoint, EndPoint = kernelendPoint}; + var kernelEndPoint = dictPoints[damEndPoint]; + kernelCurve = new GeometryCurve() {HeadPoint = kernelHeadPoint, EndPoint = kernelEndPoint}; dictCurves.Add(damCurve, kernelCurve); } soilProfile2D.Geometry.Curves.Add(kernelCurve); @@ -167,6 +182,7 @@ kernelSoilLayer2D.WaterpressureInterpolationModel = ConversionHelper.ConvertToMacroStabilityWaterpressureInterpolationModel(damSoilLayer2D.WaterpressureInterpolationModel); soilProfile2D.Surfaces.Add(kernelSoilLayer2D); } + soilProfile2D.Geometry.Rebox(); // The boundaries should be set correctly } @@ -182,8 +198,18 @@ failureMechanismParametersMStab.MStabParameters.GridPosition); } - private void TransferSoils(Data.Geotechnics.SoilProfile2D damSoilProfile2D, IList soils) + private void TransferSoils(SoilList soilList, Data.Geotechnics.SoilProfile2D damSoilProfile2D, IList soils) { + // Transfer all soils + if (soilList != null) + { + foreach (var damSoil in soilList.Soils) + { + var kernelSoil = ConversionHelper.ConvertToMacroStabilitySoil(damSoil); + dictSoils.Add(damSoil, kernelSoil); + } + } + // Harvest all soils from damSoilProfile2D foreach (SoilLayer2D surface in damSoilProfile2D.Surfaces) {