// 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.DamPipingBligh; 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; using Deltares.DamEngine.TestHelpers.Factories; using NUnit.Framework; namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.DamPipingBligh { [TestFixture] public class DamPipingBlighKernelWrapperTests { [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 location = new Location("Location 1") { SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(), ModelFactors = { UpliftCriterionPiping = 1.0 } }; location.Scenarios.Add(new DesignScenario()); var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification() { FailureMechanismSystemType = FailureMechanismSystemType.Piping, PipingModelType = PipingModelType.Bligh }; var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreateClaySandProfileForPipingBligh(); subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping; var damKernelInput = new DamKernelInput { Location = location, SubSoilScenario = subSoilScenario, RiverLevelHigh = 2.0, DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification }; var kernelWrapper = new DamPipingBlighKernelWrapper(); // 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); DamPipingBlighOutput damPipingOutput = (DamPipingBlighOutput)kernelDataOutput; Assert.AreEqual(0, messages.Count); Assert.AreEqual(4.5, damPipingOutput.FoSp, diff); Assert.AreEqual(2.25, damPipingOutput.Hc, diff); // Fill the design results var designScenario = new DesignScenario { LocationScenarioID = "1", Location = location, }; List results; kernelWrapper.PostProcess(damKernelInput, damPipingOutput, designScenario, "", out results); foreach (var result in results) { Assert.AreEqual(FailureMechanismSystemType.Piping, result.DamFailureMechanismeCalculation.FailureMechanismSystemType); Assert.AreEqual(PipingModelType.Bligh, result.DamFailureMechanismeCalculation.PipingModelType); Assert.IsNotNullOrEmpty(result.LocationName); Assert.IsNotNullOrEmpty(result.ScenarioName); Assert.IsNotNullOrEmpty(result.ProfileName); Assert.AreEqual(4.5, result.PipingDesignResults.BlighFactor, diff); Assert.AreEqual(2.25, result.PipingDesignResults.BlighHcritical, diff); Assert.AreEqual(50.5, result.PipingDesignResults.LocalExitPointX); Assert.AreEqual(0.072811999417504, 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(); location.Scenarios.Add(new DesignScenario()); location.SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(); location.ModelFactors.UpliftCriterionPiping = 1.0; var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreateClaySandProfileForPipingBligh(); subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping; 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 DamPipingBlighKernelWrapper(); IKernelDataInput kernelDataInput; IKernelDataOutput kernelDataOutput; kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput); DamPipingBlighInput damPipingInput = (DamPipingBlighInput)kernelDataInput; Assert.AreEqual(2.0, damPipingInput.HRiver, diff); Assert.AreEqual(0.0, damPipingInput.HExit, diff); Assert.AreEqual(0.3, damPipingInput.Rc, diff); Assert.AreEqual(5.0, damPipingInput.DTotal, diff); Assert.AreEqual(40.5, damPipingInput.SeepageLength, diff); Assert.AreEqual(180.0, damPipingInput.D70, diff); } [Test] public void TestValidate() { var kernelWrapper = new DamPipingBlighKernelWrapper(); // Validate without setting values. Expected error messages. var damPipingInput = new DamPipingBlighInput(); var damPipingOutput = new DamPipingBlighOutput(); 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 DamPipingBlighInput { HRiver = 1.0, HExit = 0.0, Rc = 0.3, DTotal = 2.0, SeepageLength = 40.5, D70 = 200.0, }; messages.Clear(); kernelWrapper.Validate(damPipingInput, damPipingOutput, out messages); Assert.AreEqual(0, messages.Count); } [Test] public void TestPostProcess() { var kernelWrapper = new DamPipingBlighKernelWrapper(); var subSoilScenario = new SoilGeometryProbability(); subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreateClaySandProfileForPipingBligh(); subSoilScenario.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; DamPipingBlighOutput output = new DamPipingBlighOutput { FoSp = 1.1, Hc = 2.2, ExitPointX = 3.3, UpliftFactor = 4.4, UpliftSituation = upliftSituation, CalculationResult = calculationResult }; var designScenario = new DesignScenario { LocationScenarioID = "1", Location = new Location(), }; List results; kernelWrapper.PostProcess(input, output, designScenario, "", out results); foreach (var result in results) { Assert.AreEqual(output.FoSp, result.PipingDesignResults.BlighFactor); Assert.AreEqual(output.Hc, result.PipingDesignResults.BlighHcritical); 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 Bligh")] [SetUICulture("nl-NL")] public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull() { var kernelWrapper = new DamPipingBlighKernelWrapper(); List messages; kernelWrapper.Execute(null, null, out messages); } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "No input object defined for Bligh")] [SetUICulture("en-US")] public void TestLanguageENThrowsExceptionInExecuteWhenInputIsNull() { var kernelWrapper = new DamPipingBlighKernelWrapper(); List messages; kernelWrapper.Execute(null, null, out messages); } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen uitvoer object gedefinieerd voor Bligh")] [SetUICulture("nl-NL")] public void TestThrowsExceptionInPostProcessWhenOutputIsNull() { var kernelWrapper = new DamPipingBlighKernelWrapper(); List results; kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out results); } [Test] [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen Dam invoer object gedefinieerd voor Bligh")] [SetUICulture("nl-NL")] public void TestThrowsExceptionInPostProcessWhenInputIsNull() { var kernelWrapper = new DamPipingBlighKernelWrapper(); List results; kernelWrapper.PostProcess(null, new DamPipingBlighOutput(), null, "", out results); } } }