// Copyright (C) Stichting Deltares 2019. 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.DamPipingSellmeijer4Forces; 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.Standard.Calculation; using Deltares.DamEngine.Data.Standard.Logging; using Deltares.DamEngine.TestHelpers.Factories; using NUnit.Framework; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.DamPipingSellmeijer4Forces { [TestFixture] public class DamPipingSellmeijer4ForcesTests { [Test] public void TestFullCalculation() { // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 190 // reducedFall = HRiver - HExit - (Rc * DTotal) = 1.0 - 0.0 - (0.3 * 2.0) = 0.4 // FoSbe = Hcbe / reducedFall = 4.7596 / 0.4 = 11.899 // For calculation of Hcbe see TestCanCalculateHCritical // See also "..\..\doc\Evaluation Piping\Nieuwe rekenregel bligh Sellmeijeruli.xls" const double diff = 0.0001; var location = new Location("Location 1") { SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(), ModelFactors = { UpliftCriterionPiping = 1.0 } }; var designScenario = new DesignScenario { LocationScenarioID = "1", Location = location, }; var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithOneSandlayer(); subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping; var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification() { FailureMechanismSystemType = FailureMechanismSystemType.Piping, PipingModelType = PipingModelType.Sellmeijer4Forces }; var damKernelInput = new DamKernelInput { Location = location, SubSoilScenario = subSoilScenario, RiverLevelHigh = 1.0, DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification }; var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); // Prepare the wrapper. Result is input for the calculation dll IKernelDataInput damPipingInput; IKernelDataOutput kernelDataOutput; kernelWrapper.Prepare(damKernelInput, 0, out damPipingInput, out kernelDataOutput); // Validate the input List messages; kernelWrapper.Validate(damPipingInput, kernelDataOutput, out messages); Assert.AreEqual(0, messages.Count); // Run the dll kernelWrapper.Execute(damPipingInput, kernelDataOutput, out messages); DamPipingSellmeijer4ForcesOutput damPipingOutput = (DamPipingSellmeijer4ForcesOutput) kernelDataOutput; Assert.AreEqual(0, messages.Count); Assert.AreEqual(11.899117458988467, damPipingOutput.FoSp, diff); Assert.AreEqual(4.7596469835953874, damPipingOutput.Hc, diff); // Fill the design results List results; kernelWrapper.PostProcess(damKernelInput, damPipingOutput, designScenario, "", out results); foreach (var result in results) { Assert.AreEqual(FailureMechanismSystemType.Piping, result.DamFailureMechanismeCalculation.FailureMechanismSystemType); Assert.AreEqual(PipingModelType.Sellmeijer4Forces, result.DamFailureMechanismeCalculation.PipingModelType); Assert.IsNotNullOrEmpty(result.LocationName); Assert.IsNotNullOrEmpty(result.ScenarioName); Assert.IsNotNullOrEmpty(result.ProfileName); Assert.AreEqual(11.899117458988467, result.PipingDesignResults.Sellmeijer4ForcesFactor, diff); Assert.AreEqual(4.7596469835953874, result.PipingDesignResults.Sellmeijer4ForcesHcritical, diff); Assert.AreEqual(50.5, result.PipingDesignResults.LocalExitPointX); Assert.AreEqual(0.9514101257220523, result.PipingDesignResults.UpliftFactor); Assert.AreEqual(true, result.PipingDesignResults.UpliftSituation != null && ((UpliftSituation)result.PipingDesignResults.UpliftSituation).IsUplift); Assert.AreEqual(CalculationResult.Succeeded, result.CalculationResult); Assert.AreEqual(location.SurfaceLine, result.PipingDesignResults.RedesignedSurfaceLine); } } [Test] public void TestPrepare() { const double diff = 0.0001; var location = new Location { SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(), ModelFactors = { UpliftCriterionPiping = 1.0 } }; var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithOneSandlayer(); subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping; var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification() { FailureMechanismSystemType = FailureMechanismSystemType.Piping, PipingModelType = PipingModelType.Sellmeijer4Forces }; var damKernelInput = new DamKernelInput { Location = location, SubSoilScenario = subSoilScenario, RiverLevelHigh = 1.0, DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification }; var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); IKernelDataInput kernelDataInput; IKernelDataOutput kernelDataOutput; kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); DamPipingSellmeijer4ForcesInput damPipingInput = (DamPipingSellmeijer4ForcesInput) kernelDataInput; Assert.AreEqual(1.0, damPipingInput.HRiver, diff); Assert.AreEqual(0.0, damPipingInput.HExit, diff); Assert.AreEqual(0.3, damPipingInput.Rc, diff); Assert.AreEqual(2.0, damPipingInput.DTotal, diff); Assert.AreEqual(8.0, damPipingInput.AquiferHeight, diff); Assert.AreEqual(40.5, damPipingInput.SeepageLength, diff); Assert.AreEqual(200.0, damPipingInput.D70, diff); Assert.AreEqual(0.25, damPipingInput.WhitesConstant, diff); Assert.AreEqual(37.0, damPipingInput.BeddingAngle, diff); Assert.AreEqual(1.33E-06, damPipingInput.WaterViscosity, diff); Assert.AreEqual(0.0001, damPipingInput.PermeabilityKx, diff); } [Test] public void TestValidate() { var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); // Validate without setting values. Expected error messages. var damPipingInput = new DamPipingSellmeijer4ForcesInput(); var damPipingOutput = new DamPipingSellmeijer4ForcesOutput(); List messages; kernelWrapper.Validate(damPipingInput, damPipingOutput, out messages); Assert.IsTrue(messages.Count > 0); // Validate the input when valid input is provided. Expected no messages. damPipingInput = new DamPipingSellmeijer4ForcesInput { HRiver = 1.0, HExit = 0.0, Rc = 0.3, DTotal = 2.0, AquiferHeight = 8.0, SeepageLength = 40.5, D70 = 200.0, WhitesConstant = 0.25, BeddingAngle = 37.0, WaterViscosity = 1.33E-06, PermeabilityKx = 0.0001 }; messages.Clear(); kernelWrapper.Validate(damPipingInput, damPipingOutput, out messages); Assert.AreEqual(0, messages.Count); } [Test] public void TestPostProcess() { var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithOneSandlayer(); subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping; var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification() { FailureMechanismSystemType = FailureMechanismSystemType.Piping, PipingModelType = PipingModelType.Sellmeijer4Forces }; 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; DamPipingSellmeijer4ForcesOutput output = new DamPipingSellmeijer4ForcesOutput { FoSp = 1.1, Hc = 2.2, ExitPointX = 3.3, UpliftFactor = 4.4, UpliftSituation = upliftSituation, CalculationResult = calculationResult }; var designScenario = new DesignScenario { Location = input.Location }; List results; kernelWrapper.PostProcess(input, output, designScenario, "", out results); foreach (var result in results) { Assert.AreEqual(output.FoSp, result.PipingDesignResults.Sellmeijer4ForcesFactor); Assert.AreEqual(output.Hc, result.PipingDesignResults.Sellmeijer4ForcesHcritical); Assert.AreEqual(output.ExitPointX, result.PipingDesignResults.LocalExitPointX); Assert.AreEqual(output.UpliftFactor, result.PipingDesignResults.UpliftFactor); Assert.AreEqual(output.UpliftSituation, result.PipingDesignResults.UpliftSituation); Assert.AreEqual(output.CalculationResult, result.CalculationResult); Assert.AreEqual(input.Location.SurfaceLine, result.PipingDesignResults.RedesignedSurfaceLine); } } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen invoer object gedefinieerd voor Sellmeijer 4 Krachten")] [SetUICulture("nl-NL")] public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull() { var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); List messages; kernelWrapper.Execute(null, null, out messages); } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "No input object defined for Sellmeijer 4 Forces")] [SetUICulture("en-US")] public void TestLanguageENThrowsExceptionInExecuteWhenInputIsNull() { var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); List messages; kernelWrapper.Execute(null, null, out messages); } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen uitvoer object gedefinieerd voor Sellmeijer 4 Krachten")] [SetUICulture("nl-NL")] public void TestThrowsExceptionInPostProcessWhenOutputIsNull() { var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); List results; kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out results); } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen invoer object gedefinieerd voor Sellmeijer 4 Krachten")] [SetUICulture("nl-NL")] public void TestThrowsExceptionInPostProcessWhenInputIsNull() { var kernelWrapper = new DamPipingSellmeijer4ForcesKernelWrapper(); List results; kernelWrapper.PostProcess(null, new DamPipingSellmeijer4ForcesOutput(), null, "", out results); } } }