// Copyright (C) Stichting Deltares 2024. 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.Collections.Generic; using System.Data; using System.IO; using Deltares.DamEngine.Calculators.KernelWrappers.Common; using Deltares.DamEngine.Calculators.KernelWrappers.Interfaces; using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityInwards; using Deltares.DamEngine.Calculators.Tests.KernelWrappers.TestHelpers; using Deltares.DamEngine.Data.Design; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.Results; using Deltares.DamEngine.Data.Geometry; using Deltares.DamEngine.Data.Geotechnics; using Deltares.DamEngine.Data.Standard.Calculation; using Deltares.DamEngine.Data.Standard.Logging; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using Deltares.DamEngine.TestHelpers.Factories; using NUnit.Framework; using DesignResult = Deltares.DamEngine.Data.General.Results.DesignResult; using UpliftSituation = Deltares.DamEngine.Data.General.UpliftSituation; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityInwards; [TestFixture] public class MacroStabilityInwardsKernelWrapperTests { private const string TestFolder = @"..\..\..\Deltares.DamEngine.IntegrationTests\TestFiles"; private readonly string inputXmlForDamEngine = Path.Combine(TestFolder, "StabilityDesign1Dbased.xml"); [Test] public void TestPrepare() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = MStabModelType.UpliftVan } } }; DamKernelInput kernelInput = CreateDamKernelInputForTest(); // Situation 1: no uplift. Expected PrepareResult.NotRelevant kernelInput.Location.ModelFactors.UpliftCriterionStability = 0.8; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out _, out IKernelDataOutput kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.NotRelevant)); var damMacroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(damMacroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.NoRun)); Assert.That(damMacroStabilityOutput.UpliftSituation.IsUplift, Is.EqualTo(false)); // Situation 2: there is uplift and prepare succeeds. Expected PrepareResult.Successful kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; prepareResult = kernelWrapper.Prepare(kernelInput, 0, out _, out kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.Successful)); damMacroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(damMacroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.NoRun)); Assert.That(damMacroStabilityOutput.UpliftSituation.IsUplift, Is.EqualTo(true)); // Situation 3: prepare fails. Expected PrepareResult.Failed kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.2; kernelInput.Location.SurfaceLine.CharacteristicPoints.Clear(); prepareResult = kernelWrapper.Prepare(kernelInput, 0, out _, out kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.Failed)); damMacroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(damMacroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.NoRun)); } [Test] public void TestValidate() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = MStabModelType.UpliftVan } } }; // Validate without setting values. Expected error messages. var macroStabilityInput = new MacroStabilityKernelDataInput(); var macroStabilityOutput = new MacroStabilityOutput { CalculationResult = CalculationResult.NoRun }; int errorCount = kernelWrapper.Validate(macroStabilityInput, macroStabilityOutput, out List messages); Assert.That(errorCount, Is.GreaterThan(0)); Assert.That(macroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.InvalidInputData)); // Validate the input when valid input is provided. Expected no messages. DamKernelInput kernelInput = CreateDamKernelInputForTest(); kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.Successful)); messages.Clear(); errorCount = kernelWrapper.Validate(kernelDataInput, kernelDataOutput, out messages); Assert.That(errorCount, Is.EqualTo(0)); Assert.That(((MacroStabilityOutput) kernelDataOutput).CalculationResult, Is.EqualTo(CalculationResult.NoRun)); } [Test] [TestCase(MStabModelType.Bishop)] [TestCase(MStabModelType.UpliftVan)] [TestCase(MStabModelType.BishopUpliftVan)] public void TestPostProcess(MStabModelType modelType) { var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = modelType } } }; DamKernelInput kernelInput = CreateDamKernelInputForTest(); var macroStabilityOutput = new MacroStabilityOutput { CalculationResult = CalculationResult.Succeeded, UpliftSituation = new UpliftSituation { IsUplift = true }, StabilityOutputItems = new List { new MacroStabilityOutputItem { StabilityModelType = modelType != MStabModelType.BishopUpliftVan ? modelType : MStabModelType.Bishop, CalculationResult = CalculationResult.Succeeded, SafetyFactor = 2.34, CalculationPath = TestFolder + "@\testpath", ProjectName = Path.GetFileNameWithoutExtension(inputXmlForDamEngine), ActiveCenterPoint = new Point2D(10, 10), ActiveCenterPointRadius = 8, PassiveCenterPoint = new Point2D(22, 11), PassiveCenterPointRadius = 7 } } }; if (modelType == MStabModelType.BishopUpliftVan) { var macroStabilityOutputItem = new MacroStabilityOutputItem { StabilityModelType = MStabModelType.UpliftVan, CalculationResult = CalculationResult.Succeeded, SafetyFactor = 2.01, ActiveCenterPoint = new Point2D(10, 10), ActiveCenterPointRadius = 8, PassiveCenterPoint = new Point2D(22, 11), PassiveCenterPointRadius = 7 }; macroStabilityOutput.StabilityOutputItems.Add(macroStabilityOutputItem); } var designScenario = new DesignScenario { LocationName = kernelInput.Location.Name }; var resultSlice = new StabilityResultSlice { TopLeftPoint = new Point2D(9, 3), TopRightPoint = new Point2D(9.2, 3.01), BottomLeftPoint = new Point2D(9, -3), BottomRightPoint = new Point2D(9.2, -3.1), Name = "slice1", Width = 0.2, ArcLength = 0.22, TopAngle = 0, BottomAngle = 12.2, CohesionInput = 14, CohesionOutput = 15.5, FrictionAngleInput = 30, FrictionAngleOutput = 30.5, YieldStress = 22, OCR = 23, POP = 24, DegreeOfConsolidationPorePressure = 25, PorePressureDueToDegreeOfConsolidationLoad = 26, DilatancyInput = 27, ExternalLoad = 29, HydrostaticPorePressure = 30, LeftForce = 31, LeftForceAngle = 32, LeftForceY = 33, RightForce = 34, RightForceAngle = 35, RightForceY = 36, LoadStress = 37, NormalStress = 38, PorePressure = 39, HorizontalPorePressure = 40, VerticalPorePressure = 41, PiezometricPorePressure = 42, EffectiveStress = 43, ExcessPorePressure = 44, ShearStressInput = 45, ShearStressOutput = 45.5, SoilStress = 46, TotalPorePressure = 47, TotalStress = 48, Weight = 49, SuInput = 50, SuOutput = 50.5, ShearStrengthModel = ShearStrengthModel.CPhi, HorizontalSoilQuakeStress = 51, StrengthIncreaseExponent = 52, UpliftFactor = 53, VerticalSoilQuakeStress = 54, WaterQuakeStress = 55, UpliftReductionFactor = 56, RatioCuPc = 57, ResultantForce = 58, ResultantMoment = 59, ResultantAngle = 60 }; macroStabilityOutput.StabilityOutputItems[0].ResultSlices = new List { resultSlice }; if (modelType == MStabModelType.BishopUpliftVan) { macroStabilityOutput.StabilityOutputItems[1].ResultSlices = new List { resultSlice }; } kernelWrapper.PostProcess(kernelInput, macroStabilityOutput, designScenario, "", out List results); switch (modelType) { case MStabModelType.Bishop: case MStabModelType.UpliftVan: Assert.That(results.Count, Is.EqualTo(1)); break; case MStabModelType.BishopUpliftVan: Assert.That(results.Count, Is.EqualTo(3)); break; } var expectedNumberOfIterations = new List(); var expectedStabilityModelType = new List(); var expectedSafetyFactor = new List(); switch (modelType) { case MStabModelType.Bishop: expectedNumberOfIterations = new List { 0 }; expectedStabilityModelType = new List { MStabModelType.Bishop }; expectedSafetyFactor = new List { 2.34 }; break; case MStabModelType.UpliftVan: expectedNumberOfIterations = new List { 0 }; expectedStabilityModelType = new List { MStabModelType.UpliftVan }; expectedSafetyFactor = new List { 2.34 }; break; case MStabModelType.BishopUpliftVan: expectedNumberOfIterations = new List { 0, 0, null }; expectedStabilityModelType = new List { MStabModelType.Bishop, MStabModelType.UpliftVan, MStabModelType.BishopUpliftVan }; expectedSafetyFactor = new List { 2.34, 2.01, 2.01 }; break; } for (var index = 0; index < results.Count; index++) { DesignResult result = results[index]; Assert.That(result.CalculationResult, Is.EqualTo(CalculationResult.Succeeded)); Assert.That(((UpliftSituation) result.StabilityDesignResults.UpliftSituation).IsUplift, Is.EqualTo(true)); if (index == 0) { Assert.That(result.BaseFileName, Is.EqualTo(Path.GetFileNameWithoutExtension(inputXmlForDamEngine))); Assert.That(result.CalculationSubDir, Is.EqualTo(TestFolder + "@\testpath")); } Assert.That(result.StabilityDesignResults.NumberOfIterations, Is.EqualTo(expectedNumberOfIterations[index])); Assert.That(result.StabilityDesignResults.SafetyFactor, Is.EqualTo(expectedSafetyFactor[index])); Assert.That(result.StabilityDesignResults.RedesignedSurfaceLine, Is.EqualTo(kernelInput.Location.SurfaceLine)); Assert.That(result.ProfileName, Is.EqualTo(kernelInput.SubSoilScenario.ToString())); Assert.That(result.StabilityDesignResults.StabilityModelType, Is.EqualTo(expectedStabilityModelType[index])); Assert.That(result.StabilityDesignResults.ActiveCenterPoint.X, Is.EqualTo(10)); Assert.That(result.StabilityDesignResults.ActiveCenterPoint.Z, Is.EqualTo(10)); Assert.That(result.StabilityDesignResults.ActiveCenterPointRadius, Is.EqualTo(8)); if (result.StabilityDesignResults.StabilityModelType != MStabModelType.Bishop) { Assert.That(result.StabilityDesignResults.PassiveCenterPoint.X, Is.EqualTo(22)); Assert.That(result.StabilityDesignResults.PassiveCenterPoint.Z, Is.EqualTo(11)); Assert.That(result.StabilityDesignResults.PassiveCenterPointRadius, Is.EqualTo(7)); } Assert.That(result.StabilityDesignResults.ResultSlices[0].TopLeftPoint.X, Is.EqualTo(9)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TopLeftPoint.Z, Is.EqualTo(3)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TopRightPoint.X, Is.EqualTo(9.2)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TopRightPoint.Z, Is.EqualTo(3.01)); Assert.That(result.StabilityDesignResults.ResultSlices[0].BottomLeftPoint.X, Is.EqualTo(9)); Assert.That(result.StabilityDesignResults.ResultSlices[0].BottomLeftPoint.Z, Is.EqualTo(-3)); Assert.That(result.StabilityDesignResults.ResultSlices[0].BottomRightPoint.X, Is.EqualTo(9.2)); Assert.That(result.StabilityDesignResults.ResultSlices[0].BottomRightPoint.Z, Is.EqualTo(-3.1)); Assert.That(result.StabilityDesignResults.ResultSlices[0].Name, Is.EqualTo("slice1")); Assert.That(result.StabilityDesignResults.ResultSlices[0].Width, Is.EqualTo(0.2)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ArcLength, Is.EqualTo(0.22)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TopAngle, Is.EqualTo(0)); Assert.That(result.StabilityDesignResults.ResultSlices[0].BottomAngle, Is.EqualTo(12.2)); Assert.That(result.StabilityDesignResults.ResultSlices[0].CohesionInput, Is.EqualTo(14)); Assert.That(result.StabilityDesignResults.ResultSlices[0].CohesionOutput, Is.EqualTo(15.5)); Assert.That(result.StabilityDesignResults.ResultSlices[0].FrictionAngleInput, Is.EqualTo(30)); Assert.That(result.StabilityDesignResults.ResultSlices[0].FrictionAngleOutput, Is.EqualTo(30.5)); Assert.That(result.StabilityDesignResults.ResultSlices[0].YieldStress, Is.EqualTo(22)); Assert.That(result.StabilityDesignResults.ResultSlices[0].OCR, Is.EqualTo(23)); Assert.That(result.StabilityDesignResults.ResultSlices[0].POP, Is.EqualTo(24)); Assert.That(result.StabilityDesignResults.ResultSlices[0].DegreeOfConsolidationPorePressure, Is.EqualTo(25)); Assert.That(result.StabilityDesignResults.ResultSlices[0].PorePressureDueToDegreeOfConsolidationLoad, Is.EqualTo(26)); Assert.That(result.StabilityDesignResults.ResultSlices[0].DilatancyInput, Is.EqualTo(27)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ExternalLoad, Is.EqualTo(29)); Assert.That(result.StabilityDesignResults.ResultSlices[0].HydrostaticPorePressure, Is.EqualTo(30)); Assert.That(result.StabilityDesignResults.ResultSlices[0].LeftForce, Is.EqualTo(31)); Assert.That(result.StabilityDesignResults.ResultSlices[0].LeftForceAngle, Is.EqualTo(32)); Assert.That(result.StabilityDesignResults.ResultSlices[0].LeftForceY, Is.EqualTo(33)); Assert.That(result.StabilityDesignResults.ResultSlices[0].RightForce, Is.EqualTo(34)); Assert.That(result.StabilityDesignResults.ResultSlices[0].RightForceAngle, Is.EqualTo(35)); Assert.That(result.StabilityDesignResults.ResultSlices[0].RightForceY, Is.EqualTo(36)); Assert.That(result.StabilityDesignResults.ResultSlices[0].LoadStress, Is.EqualTo(37)); Assert.That(result.StabilityDesignResults.ResultSlices[0].NormalStress, Is.EqualTo(38)); Assert.That(result.StabilityDesignResults.ResultSlices[0].PorePressure, Is.EqualTo(39)); Assert.That(result.StabilityDesignResults.ResultSlices[0].HorizontalPorePressure, Is.EqualTo(40)); Assert.That(result.StabilityDesignResults.ResultSlices[0].VerticalPorePressure, Is.EqualTo(41)); Assert.That(result.StabilityDesignResults.ResultSlices[0].PiezometricPorePressure, Is.EqualTo(42)); Assert.That(result.StabilityDesignResults.ResultSlices[0].EffectiveStress, Is.EqualTo(43)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ExcessPorePressure, Is.EqualTo(44)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ShearStressInput, Is.EqualTo(45)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ShearStressOutput, Is.EqualTo(45.5)); Assert.That(result.StabilityDesignResults.ResultSlices[0].SoilStress, Is.EqualTo(46)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TotalPorePressure, Is.EqualTo(47)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TotalStress, Is.EqualTo(48)); Assert.That(result.StabilityDesignResults.ResultSlices[0].Weight, Is.EqualTo(49)); Assert.That(result.StabilityDesignResults.ResultSlices[0].SuInput, Is.EqualTo(50)); Assert.That(result.StabilityDesignResults.ResultSlices[0].SuOutput, Is.EqualTo(50.5)); Assert.That(result.StabilityDesignResults.ResultSlices[0].HorizontalSoilQuakeStress, Is.EqualTo(51)); Assert.That(result.StabilityDesignResults.ResultSlices[0].StrengthIncreaseExponent, Is.EqualTo(52)); Assert.That(result.StabilityDesignResults.ResultSlices[0].UpliftFactor, Is.EqualTo(53)); Assert.That(result.StabilityDesignResults.ResultSlices[0].VerticalSoilQuakeStress, Is.EqualTo(54)); Assert.That(result.StabilityDesignResults.ResultSlices[0].WaterQuakeStress, Is.EqualTo(55)); Assert.That(result.StabilityDesignResults.ResultSlices[0].UpliftReductionFactor, Is.EqualTo(56)); Assert.That(result.StabilityDesignResults.ResultSlices[0].RatioCuPc, Is.EqualTo(57)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ResultantForce, Is.EqualTo(58)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ResultantMoment, Is.EqualTo(59)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ResultantAngle, Is.EqualTo(60)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ShearStrengthModel, Is.EqualTo(ShearStrengthModel.CPhi)); } } [Test] public void TestFullCalculationFails() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = MStabModelType.UpliftVan } } }; IKernelDataInput kernelDataInput = new MacroStabilityKernelDataInput(); IKernelDataOutput kernelDataOutput = new MacroStabilityOutput(); // Run the dll kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out List messages); var macroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(messages.Count, Is.GreaterThan(0)); // as there is no data at all, expect unexpected error Assert.That(macroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.UnexpectedError)); } [Test] public void TestFullCalculationSucceedsWithWarningsWithBadTangentLines() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = MStabModelType.UpliftVan } } }; // Prepare the wrapper. Result is input for the calculation dll DamKernelInput kernelInput = CreateDamKernelInputForTest(); kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; SlipCircleDefinition sd = kernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab .MStabParameters.SlipCircleDefinition; sd.UpliftVanTangentLinesDefinition = TangentLinesDefinition.Specified; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.Successful)); // Validate the input int errorCount = kernelWrapper.Validate(kernelDataInput, kernelDataOutput, out List messages); Assert.That(errorCount, Is.EqualTo(0)); // Run the dl; the tangent line position is defined in such a way that this calculation will result in // several failed attempted slip planes so there should be warnings. kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out messages); var macroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(messages.Count, Is.EqualTo(11)); Assert.That(macroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.Succeeded)); Assert.That(messages[0].Message, Does.Contain("A slice is beyond the geometry at x")); } [Test] public void TestFullCalculationSucceeds() { const double diff = 0.0001; var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = MStabModelType.UpliftVan } } }; // Prepare the wrapper. Result is input for the calculation dll DamKernelInput kernelInput = CreateDamKernelInputForTest(); // To ensure uplift occurs, set criterion to 1.4 kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.Successful)); // Validate the input int errorCount = kernelWrapper.Validate(kernelDataInput, kernelDataOutput, out List messages); Assert.That(errorCount, Is.EqualTo(0)); // Run the dll kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out messages); var macroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(messages.Count, Is.EqualTo(2)); Assert.That(macroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.Succeeded)); Assert.That(macroStabilityOutput.StabilityOutputItems.Count, Is.EqualTo(1)); Assert.That(macroStabilityOutput.StabilityOutputItems[0].SafetyFactor, Is.EqualTo(1.5211).Within(diff)); // ToDo replace by actual value when calculation is done and output is parsed // Fill the design results var designScenario = new DesignScenario { LocationName = kernelInput.Location.Name }; kernelWrapper.PostProcess(kernelInput, macroStabilityOutput, designScenario, "", out List results); Assert.That(results.Count, Is.GreaterThan(0)); foreach (DesignResult result in results) { Assert.That(result.BaseFileName, Is.EqualTo("Loc(TestLocation)_Sce(1)_Pro(DefaultNameSoilProfile1D)")); Assert.That(result.CalculationSubDir, Is.EqualTo("..\\Test\\Stability\\UpliftVan")); Assert.That(result.CalculationResult, Is.EqualTo(CalculationResult.Succeeded)); Assert.That(result.StabilityDesignResults.SafetyFactor, Is.EqualTo(1.5211).Within(diff)); Assert.That(result.StabilityDesignResults.ActiveCenterPoint.X, Is.EqualTo(50.5).Within(diff)); Assert.That(result.StabilityDesignResults.ActiveCenterPoint.Z, Is.EqualTo(12).Within(diff)); Assert.That(result.StabilityDesignResults.ActiveCenterPointRadius, Is.EqualTo(22).Within(diff)); Assert.That(result.StabilityDesignResults.PassiveCenterPoint.X, Is.EqualTo(50.5)); Assert.That(result.StabilityDesignResults.PassiveCenterPoint.Z, Is.EqualTo(2.2)); Assert.That(result.StabilityDesignResults.PassiveCenterPointRadius, Is.EqualTo(12.2)); Assert.That(result.StabilityDesignResults.ResultSlices.Count, Is.EqualTo(40)); Assert.That(result.StabilityDesignResults.ResultSlices[0].ShearStrengthModel, Is.EqualTo(ShearStrengthModel.CPhi)); Assert.That(result.StabilityDesignResults.ResultSlices[0].EffectiveStress, Is.EqualTo(15.8180658).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].FrictionAngleInput, Is.EqualTo(31).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].OCR, Is.EqualTo(double.NaN).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].NormalStress, Is.EqualTo(8.8710528).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TopLeftPoint.X, Is.EqualTo(29.9769477).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].TopLeftPoint.Z, Is.EqualTo(4.0750819).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].Width, Is.EqualTo(0.6946544).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[0].Weight, Is.EqualTo(10.9880897).Within(diff)); var index = 21; Assert.That(result.StabilityDesignResults.ResultSlices[index].ShearStrengthModel, Is.EqualTo(ShearStrengthModel.CPhi)); Assert.That(result.StabilityDesignResults.ResultSlices[index].EffectiveStress, Is.EqualTo(116.6794325).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].FrictionAngleInput, Is.EqualTo(10).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].OCR, Is.EqualTo(double.NaN).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].NormalStress, Is.EqualTo(114.2973685).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].TopLeftPoint.X, Is.EqualTo(46.8636363).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].TopLeftPoint.Z, Is.EqualTo(1.8181818).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].Width, Is.EqualTo(0.9090909).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].Weight, Is.EqualTo(193.1479678).Within(diff)); index = result.StabilityDesignResults.ResultSlices.Count - 1; Assert.That(result.StabilityDesignResults.ResultSlices[index].ShearStrengthModel, Is.EqualTo(ShearStrengthModel.CPhi)); Assert.That(result.StabilityDesignResults.ResultSlices[index].EffectiveStress, Is.EqualTo(5.5185653).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].FrictionAngleInput, Is.EqualTo(31).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].OCR, Is.EqualTo(double.NaN).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].NormalStress, Is.EqualTo(7.2892231).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].TopLeftPoint.X, Is.EqualTo(61.5363037).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].TopLeftPoint.Z, Is.EqualTo(-1.9273925).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].Width, Is.EqualTo(0.9636962).Within(diff)); Assert.That(result.StabilityDesignResults.ResultSlices[index].Weight, Is.EqualTo(10.3883614).Within(diff)); } } [Test] public void TestFullCalculationSucceedsWithBeeSwarmAsSearchMethod() { const double diff = 0.0001; var kernelWrapper = new MacroStabilityInwardsKernelWrapper { FailureMechanismParametersMStab = new FailureMechanismParametersMStab { MStabParameters = { Model = MStabModelType.UpliftVan, SearchMethod = MStabSearchMethod.BeeSwarm } } }; // Prepare the wrapper. Result is input for the calculation dll DamKernelInput kernelInput = CreateDamKernelInputForTest(); kernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab.MStabParameters .SearchMethod = MStabSearchMethod.BeeSwarm; // To ensure uplift occurs, set criterion to 1.4 kernelInput.Location.ModelFactors.UpliftCriterionStability = 1.4; PrepareResult prepareResult = kernelWrapper.Prepare(kernelInput, 0, out IKernelDataInput kernelDataInput, out IKernelDataOutput kernelDataOutput); Assert.That(prepareResult, Is.EqualTo(PrepareResult.Successful)); // Validate the input int errorCount = kernelWrapper.Validate(kernelDataInput, kernelDataOutput, out List messages); Assert.That(errorCount, Is.EqualTo(0)); // Run the dll kernelWrapper.Execute(kernelDataInput, kernelDataOutput, out messages); var macroStabilityOutput = (MacroStabilityOutput) kernelDataOutput; Assert.That(messages.Count, Is.EqualTo(3)); Assert.That(macroStabilityOutput.CalculationResult, Is.EqualTo(CalculationResult.Succeeded)); Assert.That(macroStabilityOutput.StabilityOutputItems.Count, Is.EqualTo(1)); // SafetyFactor as obtained when running the skx file with this input in the stability kernel directly = 1.9882432331086863 Assert.That(macroStabilityOutput.StabilityOutputItems[0].SafetyFactor, Is.EqualTo(1.99423).Within(diff)); // Fill the design results var designScenario = new DesignScenario { LocationName = kernelInput.Location.Name }; kernelWrapper.PostProcess(kernelInput, macroStabilityOutput, designScenario, "", out List results); Assert.That(results.Count, Is.GreaterThan(0)); } [Test] public void CalculationUpliftBasedOnDamEngineXmlWorks() { const string calcDir = "TestStabInwardsBishop"; if (Directory.Exists(calcDir)) { Directory.Delete(calcDir, true); // delete previous results } Directory.CreateDirectory(calcDir); 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 var engineInterface = new EngineInterface(inputString); Assert.That(engineInterface.DamProjectData, Is.Not.Null); engineInterface.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification.StabilityModelType = MStabModelType.UpliftVan; Output output = GeneralHelper.RunAfterInputValidation(engineInterface); Assert.That(output.Results.CalculationResults[0].StabilityDesignResults.SafetyFactor, Is.EqualTo(1.611).Within(0.001)); } [Test] [SetUICulture("nl-NL")] public void TestLanguageNLThrowsExceptionWhenInputIsNull() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper(); Assert.That(() => kernelWrapper.Execute(null, null, out _), Throws.InstanceOf().With.Message.EqualTo("Geen invoer object gedefinieerd voor Macrostabiliteit")); } [Test] [SetUICulture("en-US")] public void TestLanguageENThrowsExceptionWhenStabilityInputIsNull() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper(); Assert.That(() => kernelWrapper.Execute(null, null, out _), Throws.InstanceOf().With.Message.EqualTo("No input object defined for Macro Stability")); } [Test] [SetUICulture("nl-NL")] public void TestThrowsExceptionWhenStabilityOutputIsNull() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper(); Assert.That(() => kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out _), Throws.InstanceOf().With.Message.EqualTo("Geen uitvoer object gedefinieerd voor Macrostabiliteit")); } [Test] [SetUICulture("nl-NL")] public void TestThrowsExceptionWhenDamKernelInputIsNull() { var kernelWrapper = new MacroStabilityInwardsKernelWrapper(); Assert.That(() => kernelWrapper.PostProcess(null, null, null, "", out _), Throws.InstanceOf().With.Message.EqualTo("Geen Dam invoer object gedefinieerd voor Macrostabiliteit")); } private static DamKernelInput CreateDamKernelInputForTest() { Location location = DamEngineDataTestFactory.CreateLocation(FactoryForSurfaceLines.CreateSurfaceLineTutorial1()); // 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; location.SurfaceLine.Geometry.SyncCalcPoints(); SoilProfile1D soilProfile = DamEngineDataTestFactory.CreateSoilProfile1D(location.SoilList); SetWaterpressureInterpolationModel(soilProfile.Layers); // This test is based on a 1D profile, to be combined with the surface line. var subSoilScenario = new SoilGeometryProbability { SoilProfileType = SoilProfileType.ProfileType1D, StiFileName = "", FullStiFileName = "", SoilProfile2D = null, SegmentFailureMechanismType = SegmentFailureMechanismType.Stability, SoilProfile1D = soilProfile }; var damKernelInput = new DamKernelInput { FilenamePrefix = "Loc(TestLocation)_Sce(1)", CalculationDir = "..\\Test", Location = location, SubSoilScenario = subSoilScenario, RiverLevelLow = null, DamFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification() }; SlipCircleDefinition sd = damKernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab .MStabParameters.SlipCircleDefinition; sd.UpliftVanLeftGridHorizontalPointCount = 3; sd.UpliftVanLeftGridVerticalPointCount = 3; sd.UpliftVanLeftGridHorizontalPointDistance = 1; sd.UpliftVanLeftGridVerticalPointDistance = 1; sd.UpliftVanRightGridHorizontalPointCount = 3; sd.UpliftVanRightGridVerticalPointCount = 3; sd.UpliftVanRightGridHorizontalPointDistance = 1; sd.UpliftVanRightGridVerticalPointDistance = 1; sd.UpliftVanTangentLinesDefinition = TangentLinesDefinition.OnBoundaryLines; sd.UpliftVanTangentLinesDistance = 1; sd.GridSizeDetermination = GridSizeDetermination.Specified; damKernelInput.DamFailureMechanismeCalculationSpecification.FailureMechanismParametersMStab.MStabParameters.Model = MStabModelType.UpliftVan; return damKernelInput; } private static void SetWaterpressureInterpolationModel(IEnumerable layers) { foreach (SoilLayer1D layer in layers) { layer.WaterpressureInterpolationModel = WaterpressureInterpolationModel.Hydrostatic; } } }