Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/WtiPipingBligh/WtiPipingBlighKernelWrapperTests.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/WtiPipingBligh/WtiPipingBlighKernelWrapperTests.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/WtiPipingBligh/WtiPipingBlighKernelWrapperTests.cs (revision 6134) @@ -0,0 +1,304 @@ +// 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 Deltares.DamEngine.Calculators.KernelWrappers.Common; +using Deltares.DamEngine.Calculators.KernelWrappers.WtiPipingBligh; +using Deltares.DamEngine.Calculators.KernelWrappers.Interfaces; +using Deltares.DamEngine.Data.Design; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.General.Results; +using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Data.Standard.Calculation; +using Deltares.DamEngine.Data.Standard.Logging; +using Deltares.DamEngine.TestHelpers.Factories; +using NUnit.Framework; + +namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.WtiPipingBligh; + +[TestFixture] +public class WtiPipingBlighKernelWrapperTests +{ + [Test] + public void TestFullCalculation() + { + // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 190 + // Hcbe = SeepageLength / CreepFactor = 40.5 / 18 = 2.25 + // CreepFactor is calculated with D70 + // reducedFall = HRiver - HExit - (Rc * DTotal) = 2.0 - 0.0 - (0.3 * 5.0) = 0.5 + // FoSbe = Hcbe / reducedFall = 2.25 / 0.5 + + const double diff = 0.0001; + + var subSoilScenario = new SoilGeometryProbability + { + SoilProfile1D = FactoryForSoilProfiles.CreateClaySandProfileForPipingBligh(out SoilList soilList), + SegmentFailureMechanismType = SegmentFailureMechanismType.Piping + }; + + var location = new Location("Location 1") + { + SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(), + ModelFactors = + { + UpliftCriterionPiping = 1.0 + }, + CurrentScenario = new DesignScenario(), + DikeEmbankmentMaterial = soilList.Soils[0].Name, + SoilList = soilList + }; + var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification + { + FailureMechanismSystemType = FailureMechanismSystemType.Piping, + PipingModelType = PipingModelType.Bligh + }; + + var damKernelInput = new DamKernelInput + { + Location = location, + SubSoilScenario = subSoilScenario, + RiverLevelHigh = 2.0, + DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification + }; + + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + + // Prepare the wrapper. Result is input for the calculation dll + IKernelDataInput wtiPipingInput; + IKernelDataOutput kernelDataOutput; + kernelWrapper.Prepare(damKernelInput, 0, out wtiPipingInput, out kernelDataOutput); + + // Validate the input + List messages; + kernelWrapper.Validate(wtiPipingInput, kernelDataOutput, out messages); + Assert.That(messages, Is.Empty); + + // Run the dll + kernelWrapper.Execute(wtiPipingInput, kernelDataOutput, out messages); + var wtiPipingBlighOutput = (WtiPipingBlighOutput) kernelDataOutput; + Assert.Multiple(() => + { + Assert.That(messages, Is.Empty); + Assert.That(wtiPipingBlighOutput.FoSp, Is.EqualTo(4.5).Within(diff)); + Assert.That(wtiPipingBlighOutput.Hc, Is.EqualTo(2.25).Within(diff)); + }); + + // Fill the design results + var designScenario = new DesignScenario + { + LocationScenarioID = "1", + LocationName = location.Name + }; + List results; + kernelWrapper.PostProcess(damKernelInput, wtiPipingBlighOutput, designScenario, "", out results); + foreach (DesignResult result in results) + { + Assert.Multiple(() => + { + Assert.That(result.DamFailureMechanismeCalculation.FailureMechanismSystemType, Is.EqualTo(FailureMechanismSystemType.Piping)); + Assert.That(result.DamFailureMechanismeCalculation.PipingModelType, Is.EqualTo(PipingModelType.Bligh)); + Assert.That(result.LocationName, Is.Not.Null.Or.Empty); + Assert.That(result.ScenarioName, Is.Not.Null.Or.Empty); + Assert.That(result.ProfileName, Is.Not.Null.Or.Empty); + Assert.That(result.PipingDesignResults.BlighFactor, Is.EqualTo(4.5).Within(diff)); + Assert.That(result.PipingDesignResults.BlighHcritical, Is.EqualTo(2.25).Within(diff)); + + Assert.That(result.PipingDesignResults.LocalExitPointX, Is.EqualTo(50.5)); + Assert.That(result.PipingDesignResults.UpliftFactor, Is.EqualTo(0.072811999417504)); + Assert.That(result.PipingDesignResults.UpliftSituation != null && ((UpliftSituation)result.PipingDesignResults.UpliftSituation).IsUplift, Is.EqualTo(true)); + Assert.That(result.CalculationResult, Is.EqualTo(CalculationResult.Succeeded)); + + Assert.That(result.PipingDesignResults.RedesignedSurfaceLine, Is.EqualTo(location.SurfaceLine)); + }); + } + } + + [Test] + public void TestPrepare() + { + const double diff = 0.0001; + + var subSoilScenario = new SoilGeometryProbability + { + SoilProfile1D = FactoryForSoilProfiles.CreateClaySandProfileForPipingBligh(out SoilList soilList), + SegmentFailureMechanismType = SegmentFailureMechanismType.Piping + }; + + var location = new Location + { + SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(), + ModelFactors = + { + UpliftCriterionPiping = 1.0 + }, + CurrentScenario = new DesignScenario(), + DikeEmbankmentMaterial = soilList.Soils[0].Name, + SoilList = soilList + }; + + var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification + { + FailureMechanismSystemType = FailureMechanismSystemType.Piping, + PipingModelType = PipingModelType.Bligh + }; + var damKernelInput = new DamKernelInput + { + Location = location, + SubSoilScenario = subSoilScenario, + RiverLevelHigh = 2.0, + DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification + }; + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + IKernelDataInput kernelDataInput; + kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out IKernelDataOutput _); + var wtiPipingBlighInput = (WtiPipingBlighInput) kernelDataInput; + Assert.Multiple(() => + { + Assert.That(wtiPipingBlighInput.HRiver, Is.EqualTo(2.0).Within(diff)); + Assert.That(wtiPipingBlighInput.HExit, Is.EqualTo(0.0).Within(diff)); + Assert.That(wtiPipingBlighInput.Rc, Is.EqualTo(0.3).Within(diff)); + Assert.That(wtiPipingBlighInput.DTotal, Is.EqualTo(5.0).Within(diff)); + Assert.That(wtiPipingBlighInput.SeepageLength, Is.EqualTo(40.5).Within(diff)); + Assert.That(wtiPipingBlighInput.D70, Is.EqualTo(180.0).Within(diff)); + }); + } + + [Test] + public void TestValidate() + { + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + + // Validate without setting values. Expected error messages. + var wtiPipingBlighInput = new WtiPipingBlighInput(); + var wtiPipingBlighOutput = new WtiPipingBlighOutput(); + List messages; + kernelWrapper.Validate(wtiPipingBlighInput, wtiPipingBlighOutput, out messages); + Assert.That(messages, Is.Not.Empty); + + // Validate the input when valid input is provided. Expected no messages. + wtiPipingBlighInput = new WtiPipingBlighInput + { + HRiver = 1.0, + HExit = 0.0, + Rc = 0.3, + DTotal = 2.0, + SeepageLength = 40.5, + D70 = 200.0 + }; + messages.Clear(); + kernelWrapper.Validate(wtiPipingBlighInput, wtiPipingBlighOutput, out messages); + Assert.That(messages, Is.Empty); + } + + [Test] + public void TestPostProcess() + { + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + + var subSoilScenario = new SoilGeometryProbability + { + SoilProfile1D = FactoryForSoilProfiles.CreateClaySandProfileForPipingBligh(out _), + SegmentFailureMechanismType = SegmentFailureMechanismType.Piping + }; + var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification + { + FailureMechanismSystemType = FailureMechanismSystemType.Piping, + PipingModelType = PipingModelType.Bligh + }; + var input = new DamKernelInput + { + Location = new Location(), + SubSoilScenario = subSoilScenario, + DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification + }; + input.Location = new Location(); + + var upliftSituation = new UpliftSituation(); + upliftSituation.IsUplift = true; + var calculationResult = CalculationResult.Succeeded; + var output = new WtiPipingBlighOutput + { + FoSp = 1.1, + Hc = 2.2, + ExitPointX = 3.3, + UpliftFactor = 4.4, + UpliftSituation = upliftSituation, + CalculationResult = calculationResult + }; + + var designScenario = new DesignScenario + { + LocationScenarioID = "1", + LocationName = "nieuw" + }; + List results; + kernelWrapper.PostProcess(input, output, designScenario, "", out results); + foreach (DesignResult result in results) + { + Assert.That(result.PipingDesignResults.BlighFactor, Is.EqualTo(output.FoSp)); + Assert.That(result.PipingDesignResults.BlighHcritical, Is.EqualTo(output.Hc)); + + Assert.That(result.PipingDesignResults.LocalExitPointX, Is.EqualTo(output.ExitPointX)); + Assert.That(result.PipingDesignResults.UpliftFactor, Is.EqualTo(output.UpliftFactor)); + Assert.That(result.PipingDesignResults.UpliftSituation, Is.EqualTo(output.UpliftSituation)); + Assert.That(result.CalculationResult, Is.EqualTo(output.CalculationResult)); + + Assert.That(result.PipingDesignResults.RedesignedSurfaceLine, Is.EqualTo(input.Location.SurfaceLine)); + } + } + + [Test] + [SetUICulture("nl-NL")] + public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull() + { + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + List messages; + Assert.That(() => kernelWrapper.Execute(null, null, out messages), Throws.InstanceOf().With.Message.EqualTo("Geen invoer object gedefinieerd voor Bligh")); + } + + [Test] + [SetUICulture("en-US")] + public void TestLanguageENThrowsExceptionInExecuteWhenInputIsNull() + { + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + List messages; + Assert.That(() => kernelWrapper.Execute(null, null, out messages), Throws.InstanceOf().With.Message.EqualTo("No input object defined for Bligh")); + } + + [Test] + [SetUICulture("nl-NL")] + public void TestThrowsExceptionInPostProcessWhenOutputIsNull() + { + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + List results; + Assert.That(() => kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out results), Throws.InstanceOf().With.Message.EqualTo("Geen uitvoer object gedefinieerd voor Bligh")); + } + + [Test] + [SetUICulture("nl-NL")] + public void TestThrowsExceptionInPostProcessWhenInputIsNull() + { + var kernelWrapper = new WtiPipingBlighKernelWrapper(); + List results; + Assert.That(() => kernelWrapper.PostProcess(null, new WtiPipingBlighOutput(), null, "", out results), Throws.InstanceOf().With.Message.EqualTo("Geen Dam invoer object gedefinieerd voor Bligh")); + } +} \ No newline at end of file Fisheye: Tag 6134 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamPipingBligh/WtiPipingBlighKernelWrapperTests.cs'. Fisheye: No comparison available. Pass `N' to diff?