Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityInwards/MacroStabilityInwardsKernelWrapperTests.cs =================================================================== diff -u -r3082 -r3238 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityInwards/MacroStabilityInwardsKernelWrapperTests.cs (.../MacroStabilityInwardsKernelWrapperTests.cs) (revision 3082) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityInwards/MacroStabilityInwardsKernelWrapperTests.cs (.../MacroStabilityInwardsKernelWrapperTests.cs) (revision 3238) @@ -34,9 +34,7 @@ using Deltares.DamEngine.Io; using Deltares.DamEngine.TestHelpers; using Deltares.DamEngine.TestHelpers.Factories; -using Deltares.MacroStability.CSharpWrapper.Input; using NUnit.Framework; -using NUnit.Framework.Constraints; using CharacteristicPointType = Deltares.DamEngine.Data.Geotechnics.CharacteristicPointType; using LogMessage = Deltares.DamEngine.Data.Standard.Logging.LogMessage; using MacroStabilityOutput = Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards.MacroStabilityOutput; @@ -52,14 +50,15 @@ [Test] public void TestPrepare() { - var kernelWrapper = new MacroStabilityInwardsKernelWrapper(); - kernelWrapper.FailureMechanismParametersMStab = new FailureMechanismParametersMStab(); + var kernelWrapper = new MacroStabilityInwardsKernelWrapper + { + FailureMechanismParametersMStab = new FailureMechanismParametersMStab() + }; IKernelDataInput kernelDataInput; IKernelDataOutput kernelDataOutput; var kernelInput = CreateDamKernelInputForTest(); - kernelInput.SubSoilScenario.SoilProfile2D.Surfaces[0].IsAquifer = false; - + // Situation 1: no uplift. Expected PrepareResult.NotRelevant kernelInput.Location.ModelFactors.UpliftCriterionStability = 0.8; var prepareResult = kernelWrapper.Prepare(kernelInput, 0, out kernelDataInput, out kernelDataOutput); @@ -69,7 +68,7 @@ Assert.AreEqual(false, damMacroStabilityOutput.UpliftSituation.IsUplift); // Situation 2: there is uplift and prepare succeeds. Expected PrepareResult.Successful - kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.2; + kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; prepareResult = kernelWrapper.Prepare(kernelInput, 0, out kernelDataInput, out kernelDataOutput); Assert.AreEqual(PrepareResult.Successful, prepareResult); damMacroStabilityOutput = (MacroStabilityOutput)kernelDataOutput; @@ -102,8 +101,7 @@ // Validate the input when valid input is provided. Expected no messages. var kernelInput = CreateDamKernelInputForTest(); - kernelInput.SubSoilScenario.SoilProfile2D.Surfaces[0].IsAquifer = false; - kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.2; + kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; var prepareResult = kernelWrapper.Prepare(kernelInput, 0, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput); Assert.IsTrue(prepareResult == PrepareResult.Successful); messages.Clear(); @@ -162,14 +160,18 @@ } [Test] - public void TestFullCalculationFailsWithNoGrid() + public void TestFullCalculationFailsWithBadTangentLines() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper(); kernelWrapper.FailureMechanismParametersMStab = new FailureMechanismParametersMStab(); // Prepare the wrapper. Result is input for the calculation dll var kernelInput = CreateDamKernelInputForTest(); - kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.2; + kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; + var sd = kernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab + .MStabParameters.SlipCircleDefinition; + + sd.UpliftVanTangentLinesDefinition = TangentLinesDefinition.OnBoundaryLines; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput); Assert.AreEqual(PrepareResult.Successful, prepareResult); @@ -178,16 +180,15 @@ var errorCount = kernelWrapper.Validate(kernelDataInput, kernelDataOutput, out messages); Assert.IsTrue(errorCount == 0); - // Run the dl; the grid position is defined i such a way that no valid circles can be found during calculation so this should fail. + // Run the dl; the tangent line position is defined in such a way that a circle segment can not be matched to a soil this should fail. kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out messages); MacroStabilityOutput macroStabilityOutput = (MacroStabilityOutput)kernelDataOutput; - Assert.AreEqual(149, messages.Count); - Assert.AreEqual(CalculationResult.RunFailed, macroStabilityOutput.CalculationResult); - Assert.AreEqual("The kernel was not able to determine valid slip circles or slip planes.", messages[148].Message); + Assert.AreEqual(1, messages.Count); + Assert.AreEqual(CalculationResult.UnexpectedError, macroStabilityOutput.CalculationResult); + Assert.IsTrue(messages[0].Message.Contains("A slice is beyond the geometry at x")); } [Test] - [Category(Categories.WorkInProgress)] // check input and result public void TestFullCalculationSucceeds() { const double diff = 0.0001; @@ -199,7 +200,8 @@ IKernelDataInput kernelDataInput; IKernelDataOutput kernelDataOutput; var kernelInput = CreateDamKernelInputForTest(); - kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.2; + // To ensure uplift occurs, set criterion to 1.4 + kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out kernelDataInput, out kernelDataOutput); Assert.AreEqual(PrepareResult.Successful, prepareResult); @@ -211,10 +213,10 @@ // Run the dll kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out messages); MacroStabilityOutput macroStabilityOutput = (MacroStabilityOutput)kernelDataOutput; - Assert.AreEqual(0, messages.Count); + Assert.AreEqual(2, messages.Count); Assert.AreEqual(CalculationResult.Succeeded, macroStabilityOutput.CalculationResult); Assert.AreEqual(1, macroStabilityOutput.StabilityOutputItems.Count); - Assert.AreEqual(1.357, macroStabilityOutput.StabilityOutputItems[0].SafetyFactor, diff); // ToDo replace by actual value when calculation is done and output is parsed + Assert.AreEqual(1.5211, macroStabilityOutput.StabilityOutputItems[0].SafetyFactor, diff); // ToDo replace by actual value when calculation is done and output is parsed // Fill the design results @@ -228,8 +230,7 @@ foreach (var result in results) { Assert.AreEqual(CalculationResult.Succeeded, result.CalculationResult); - Assert.AreEqual(1.357, result.StabilityDesignResults.SafetyFactor); - // ToDo: Add all output items when it is clear what parts of StabilityDesignResults will be filled + Assert.AreEqual(1.5211, result.StabilityDesignResults.SafetyFactor, diff); } } @@ -246,9 +247,6 @@ string inputString = File.ReadAllText(inputXmlForDamEngine); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used - //inputString = XmlAdapter.ChangeValueInXml(inputString, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); - //inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); - // inputString = XmlAdapter.ChangeValueInXml(inputString, "SegmentFailureMechanismType", segmentFailureMechanismType.ToString()); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); @@ -261,7 +259,6 @@ } [Test] - [Category(Categories.WorkInProgress)] // check input and result public void CalculationUpliftBasedOnDamEngineXmlWorks() { const string calcDir = "TestStabInwardsBishop"; @@ -274,9 +271,6 @@ string inputString = File.ReadAllText(inputXmlForDamEngine); inputString = XmlAdapter.ChangeValueInXml(inputString, "ProjectPath", ""); // Current directory will be used inputString = XmlAdapter.ChangeValueInXml(inputString, "CalculationMap", calcDir); // Current directory will be used - //inputString = XmlAdapter.ChangeValueInXml(inputString, "MapForSoilgeometries2D", @"TestFiles\DAM Tutorial Design.geometries2D.0\"); - //inputString = XmlAdapter.ChangeValueInXml(inputString, "SoilDatabaseName", @"TestFiles\DAM Tutorial Design0.soilmaterials.mdb"); - //inputString = XmlAdapter.ChangeValueInXml(inputString, "SegmentFailureMechanismType", segmentFailureMechanismType.ToString()); EngineInterface engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); engineInterface.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.StabilityModelType = @@ -286,7 +280,7 @@ Assert.IsNotNull(outputString); var output = DamXmlSerialization.LoadOutputFromXmlString(outputString); Assert.IsNotNull(output.Results.CalculationResults, "No results available"); - Assert.AreEqual(1.282, output.Results.CalculationResults[0].StabilityDesignResults.SafetyFactor, 0.1); + Assert.AreEqual(1.494, output.Results.CalculationResults[0].StabilityDesignResults.SafetyFactor, 0.001); } [Test] @@ -332,28 +326,30 @@ private static DamKernelInput CreateDamKernelInputForTest() { var location = DamEngineDataTestFactory.CreateLocation(FactoryForSurfaceLines.CreateSurfaceLineTutorial1()); - // Correction needed in order to make surface line as lengthy as the geometry is wide (100 meter wide). - location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.SurfaceLevelInside).X = - 100; + // Correction needed in order to make surface line as lengthy as needed to perform a proper calculation. + location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.SurfaceLevelInside).X = 100; // Correction needed in order to make surface line points strictly increasing increasing (ditch was vertical at polderside, - // now this not allowed by the kernel validator!) So that needs to be fixed in the kernel. - location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DitchPolderSide).X = - 62.5; + // now this not allowed by the kernel validator!) So that needs to be fixed in the kernel). + location.SurfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DitchPolderSide).X = 62.5; location.SurfaceLine.Geometry.SyncCalcPoints(); + + // This test is based on a 1D profile, to be combined with the surface line. var subSoilScenario = new SoilGeometryProbability(); - subSoilScenario.SoilProfileType = SoilProfileType.ProfileType2D; + subSoilScenario.SoilProfileType = SoilProfileType.ProfileType1D; subSoilScenario.StiFileName = ""; subSoilScenario.FullStiFileName = ""; - subSoilScenario.SoilProfile2D = DamEngineDataTestFactory.CreateSoilProfile2D(location.SoilList); + subSoilScenario.SoilProfile2D = null; subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Stability; - subSoilScenario.SoilProfile1D = DamEngineDataTestFactory.CreateSoilProfile1D(); + subSoilScenario.SoilProfile1D = DamEngineDataTestFactory.CreateSoilProfile1D(location.SoilList); - var damKernelInput = new DamKernelInput(); - damKernelInput.Location = location; - damKernelInput.SubSoilScenario = subSoilScenario; - damKernelInput.RiverLevelLow = null; - damKernelInput.DamFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification(); + var damKernelInput = new DamKernelInput + { + Location = location, + SubSoilScenario = subSoilScenario, + RiverLevelLow = null, + DamFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification() + }; var sd = damKernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab .MStabParameters.SlipCircleDefinition; sd.UpliftVanLeftGridHorizontalPointCount = 3; @@ -364,9 +360,11 @@ sd.UpliftVanRightGridVerticalPointCount = 3; sd.UpliftVanRightGridHorizontalPointDistance = 1; sd.UpliftVanRightGridVerticalPointDistance = 1; - sd.UpliftVanTangentLinesDefinition = TangentLinesDefinition.Specified; + sd.UpliftVanTangentLinesDefinition = TangentLinesDefinition.OnBoundaryLines; sd.UpliftVanTangentLinesDistance = 1; sd.GridSizeDetermination = GridSizeDetermination.Specified; + damKernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab.MStabParameters.Model = + MStabModelType.UpliftVan; return damKernelInput; }