Index: dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj =================================================================== diff -u -r745 -r748 --- dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 745) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 748) @@ -51,6 +51,7 @@ + Index: dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamPipingSellmeijerVnk/DamPipingSellmeijerVnkKernelWrapperTests.cs =================================================================== diff -u --- dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamPipingSellmeijerVnk/DamPipingSellmeijerVnkKernelWrapperTests.cs (revision 0) +++ dam engine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/DamPipingSellmeijerVnk/DamPipingSellmeijerVnkKernelWrapperTests.cs (revision 748) @@ -0,0 +1,367 @@ +// Copyright (C) Stichting Deltares 2017. 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; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Deltares.DamEngine.Calculators.KernelWrappers.Common; +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.Geometry; +using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.Data.Standard.Logging; +using NUnit.Framework; + +namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.DamPipingSellmeijerVnk +{ + [TestFixture] + public class DamPipingSellmeijerVnkKernelWrapperTests + { + [Test] + public void TestFullCalculation() + { + // expected results are based on test in 'https://repos.deltares.nl/repos/dam/dam classic' revision 190 + // See dgs-as2.geodelft.nl/DGWebPiping for calculation + // =========== + // gamma_w = 9.81 + // mu = 1.33E-06 + // gamma_p = 26.5 + // eta = 0.25 + // theta = 37 + // F = 1.2 + // i = 0.3 + // =========== + // D1 = dikte bovenste zandlaag = 2.0 + // D2 = dikte onderste zandlaag = 6.0 + // k1 = 0.0001 + // k2 = 0.0002 + // k3 = 0.0001 + // Do = 2.0 + // D70 = 200 + // Calculate dH + // L = ToeOfDike.x - entrypoint.x = 50.5 - 10.0 = 40.5 + // =========== + + // reducedFall = HRiver - HExit = 1.0 - 0.0 = 1.0 + // FoSp = Hc / reducedFall = 3.65 / 1.0 = 3.65 + // Hc is calculated with external dll + + const double diff = 0.01; + + var location = new Location("Location 1") + { + SurfaceLine = CreateSurfaceLineTutorial1() + }; + + var designScenario = new DesignScenario + { + LocationScenarioID = "1", + Location = location, + RiverLevel = 1.0, + ModelFactors = + { + UpliftCriterionPiping = 1.0 + } + }; + + var subSoilScenario = new SoilGeometryProbability(); + subSoilScenario.SoilProfile1D = CreatePipingSellmeijerProfileWithTwoSandlayers(); + subSoilScenario.SegmentFailureMechanismType = FailureMechanismSystemType.Piping; + + var damKernelInput = new DamKernelInput + { + DesignScenario = designScenario, + Location = location, + SubSoilScenario = subSoilScenario + }; + +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); +// +// // Prepare the wrapper. Result is input for the calculation dll +// IKernelDataInput damPipingInput; +// IKernelDataOutput kernelDataOutput; +// kernelWrapper.Prepare(damKernelInput, 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); +// DamPipingSellmeijerVnkOutput damPipingOutput = (DamPipingSellmeijerVnkOutput)kernelDataOutput; +// Assert.AreEqual(0, messages.Count); +// Assert.AreEqual(3.65, damPipingOutput.FoSp, diff); +// Assert.AreEqual(3.65, damPipingOutput.Hc, diff); +// +// // Fill the design results +// DesignResult result; +// kernelWrapper.PostProcess(damKernelInput, damPipingOutput, "", out result); +// Assert.AreEqual(FailureMechanismSystemType.Piping, result.DamFailureMechanismeCalculation.FailureMechanismSystemType); +// Assert.AreEqual(PipingModelType.SellmeijerVnk, result.DamFailureMechanismeCalculation.PipingModelType); +// Assert.IsNotNullOrEmpty(result.LocationName); +// Assert.IsNotNullOrEmpty(result.ScenarioName); +// Assert.IsNotNullOrEmpty(result.ProfileName); +// Assert.AreEqual(3.65, result.PipingDesignResults.SellmeijerVnkFactor, diff); +// Assert.AreEqual(3.65, result.PipingDesignResults.SellmeijerVnkHcritical, diff); + } + + [Test] + public void TestPrepare() + { + const double diff = 0.0001; + + var designScenario = new DesignScenario(); + designScenario.Location = new Location(); + designScenario.RiverLevel = 1.0; + designScenario.ModelFactors.UpliftCriterionPiping = 1.0; + + var location = new Location(); + location.SurfaceLine = CreateSurfaceLineTutorial1(); + + var subSoilScenario = new SoilGeometryProbability(); + subSoilScenario.SoilProfile1D = CreatePipingSellmeijerProfileWithTwoSandlayers(); + subSoilScenario.SegmentFailureMechanismType = FailureMechanismSystemType.Piping; + + var damKernelInput = new DamKernelInput + { + DesignScenario = designScenario, + Location = location, + SubSoilScenario = subSoilScenario + }; +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); + IKernelDataInput kernelDataInput; + IKernelDataOutput kernelDataOutput; +// kernelWrapper.Prepare(damKernelInput, out kernelDataInput, out kernelDataOutput); +// DamPipingSellmeijerVnkInput damPipingInput = (DamPipingSellmeijerVnkInput)kernelDataInput; +// Assert.AreEqual(1.0, damPipingInput.HRiver, diff); +// Assert.AreEqual(0.0, damPipingInput.HExit, diff); +// Assert.AreEqual(0.0, damPipingInput.PolderLevel, diff); +// Assert.AreEqual(0.0, damPipingInput.SurfaceLevel, diff); +// Assert.AreEqual(0.3, damPipingInput.Rc, diff); +// Assert.AreEqual(2.0, damPipingInput.DTotal, diff); +// Assert.AreEqual(2.0, damPipingInput.DInBetweenAquiferlayer, diff); +// Assert.AreEqual(6.0, damPipingInput.DBottomAquiferlayer, diff); +// Assert.AreEqual(0.0001, damPipingInput.PermeabilityInBetweenAquiferlayer, diff); +// Assert.AreEqual(0.0002, damPipingInput.PermeabilityBottomAquiferlayer, 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); + } + + [Test] + public void TestValidate() + { +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); +// +// // Validate without setting values. Expected error messages. +// var damPipingInput = new DamPipingSellmeijerVnkInput(); +// var damPipingOutput = new DamPipingSellmeijerVnkOutput(); +// 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 DamPipingSellmeijerVnkInput +// { +// HRiver = 1.0, +// HExit = 0.0, +// PolderLevel = 0.0, +// SurfaceLevel = 0.0, +// Rc = 0.3, +// DTotal = 2.0, +// DInBetweenAquiferlayer = 2.0, +// DBottomAquiferlayer = 6.0, +// PermeabilityInBetweenAquiferlayer = 0.0001, +// PermeabilityBottomAquiferlayer = 0.0002, +// 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 DamPipingSellmeijerVnkKernelWrapper(); + + var subSoilScenario = new SoilGeometryProbability(); + subSoilScenario.SoilProfile1D = CreatePipingSellmeijerProfileWithTwoSandlayers(); + subSoilScenario.SegmentFailureMechanismType = FailureMechanismSystemType.Piping; + var input = new DamKernelInput + { + DesignScenario = new DesignScenario(), + Location = new Location(), + SubSoilScenario = subSoilScenario + }; + input.DesignScenario.Location = new Location(); + +// DamPipingSellmeijerVnkOutput output = new DamPipingSellmeijerVnkOutput +// { +// FoSp = 1.1, +// Hc = 2.2 +// }; + + DesignResult result; +// kernelWrapper.PostProcess(input, output, "", out result); +// Assert.AreEqual(output.FoSp, result.PipingDesignResults.SellmeijerVnkFactor); +// Assert.AreEqual(output.Hc, result.PipingDesignResults.SellmeijerVnkHcritical); + } + + [Test] + [Category(Categories.WorkInProgress)] + [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen invoer object gedefinieerd voor Sellmeijer VNK")] + [SetUICulture("nl-NL")] + public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull() + { +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); +// List messages; +// kernelWrapper.Execute(null, null, out messages); + } + + [Test] + [Category(Categories.WorkInProgress)] + [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "No input object defined for Sellmeijer VNK")] + [SetUICulture("en-US")] + public void TestLanguageENThrowsExceptionInExecuteWhenInputIsNull() + { +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); +// List messages; +// kernelWrapper.Execute(null, null, out messages); + } + + [Test] + [Category(Categories.WorkInProgress)] + [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen uitvoer object gedefinieerd voor Sellmeijer VNK")] + [SetUICulture("nl-NL")] + public void TestThrowsExceptionInPostProcessWhenOutputIsNull() + { +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); +// DesignResult result; +// kernelWrapper.PostProcess(new DamKernelInput(), null, "", out result); + } + + [Test] + [Category(Categories.WorkInProgress)] + [ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen invoer object gedefinieerd voor Sellmeijer VNK")] + [SetUICulture("nl-NL")] + public void TestThrowsExceptionInPostProcessWhenInputIsNull() + { +// var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper(); +// DesignResult result; +// kernelWrapper.PostProcess(null, new DamPipingSellmeijerVnkOutput(), "", out result); + } + + + public static SoilProfile1D CreatePipingSellmeijerProfileWithTwoSandlayers() + { + SoilProfile1D soilProfile1D = new SoilProfile1D(); + SoilLayer1D soilLayer1D1 = new SoilLayer1D(); + soilLayer1D1.Name = "L0"; + soilLayer1D1.TopLevel = 10.0; + soilLayer1D1.Soil = new Soil("Topmaterial", 1.0, 1.0); + soilLayer1D1.Soil.PermeabKx = 0.0003; + soilLayer1D1.Soil.DiameterD70 = 0.0003; + soilLayer1D1.Soil.WhitesConstant = 0.5; + soilLayer1D1.Soil.BeddingAngle = 57.0; + soilLayer1D1.Soil.DryUnitWeight = 0.01; + soilLayer1D1.IsAquifer = false; + soilProfile1D.Layers.Add(soilLayer1D1); + + SoilLayer1D soilLayer1D2 = new SoilLayer1D(); + soilLayer1D2.Name = "L1"; + soilLayer1D2.TopLevel = -2.0; + soilLayer1D2.Soil = new Soil("Sand upper", 22.0, 20.0); + soilLayer1D2.Soil.PermeabKx = 0.0001; + soilLayer1D2.Soil.DiameterD70 = 0.0002; + soilLayer1D2.Soil.WhitesConstant = 0.25; + soilLayer1D2.Soil.BeddingAngle = 37.0; + soilLayer1D2.Soil.DryUnitWeight = 0.01; + soilLayer1D2.IsAquifer = true; + soilProfile1D.Layers.Add(soilLayer1D2); + + SoilLayer1D soilLayer1D3 = new SoilLayer1D(); + soilLayer1D3.Name = "L2"; + soilLayer1D3.TopLevel = -3.99; + soilLayer1D3.Soil = new Soil("Clay", 22.0, 20.0); + soilLayer1D3.Soil.PermeabKx = 0.0001; + soilLayer1D3.Soil.DiameterD70 = 0.0002; + soilLayer1D3.Soil.WhitesConstant = 0.25; + soilLayer1D3.Soil.BeddingAngle = 37.0; + soilLayer1D3.Soil.DryUnitWeight = 0.01; + soilLayer1D3.IsAquifer = false; + soilProfile1D.Layers.Add(soilLayer1D3); + + SoilLayer1D soilLayer1D4 = new SoilLayer1D(); + soilLayer1D4.Name = "L3"; + soilLayer1D4.TopLevel = -4.0; + soilLayer1D4.Soil = new Soil("Sand lower", 22.0, 20.0); + soilLayer1D4.Soil.PermeabKx = 0.0002; + soilLayer1D4.Soil.DiameterD70 = 0.0003; + soilLayer1D4.Soil.WhitesConstant = 0.35; + soilLayer1D4.Soil.BeddingAngle = 47.0; + soilLayer1D4.Soil.DryUnitWeight = 0.01; + soilLayer1D4.IsAquifer = true; + soilProfile1D.Layers.Add(soilLayer1D4); + soilProfile1D.BottomLevel = -10.0; + return soilProfile1D; + } + + private static SurfaceLine2 CreateSurfaceLineTutorial1(bool includingTraffic = false) + { + SurfaceLine2 surfaceLine2 = new SurfaceLine2(); + surfaceLine2.Name = "Tutorial1"; + surfaceLine2.Geometry = new GeometryPointString(); + surfaceLine2.CharacteristicPoints.GeometryMustContainPoint = true; + SurfaceLine2 line = surfaceLine2; + line.EnsurePointOfType(0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); + line.EnsurePointOfType(10.0, 0.0, CharacteristicPointType.DikeToeAtRiver); + line.EnsurePointOfType(34.5, 5.0, CharacteristicPointType.DikeTopAtRiver); + if (includingTraffic) + { + line.EnsurePointOfType(35.0, 5.0, CharacteristicPointType.TrafficLoadOutside); + line.EnsurePointOfType(38.5, 5.0, CharacteristicPointType.TrafficLoadInside); + } + line.EnsurePointOfType(40.5, 5.0, CharacteristicPointType.DikeTopAtPolder); + line.EnsurePointOfType(50.5, 0.0, CharacteristicPointType.DikeToeAtPolder); + line.EnsurePointOfType(58.5, 0.0, CharacteristicPointType.DitchDikeSide); + line.EnsurePointOfType(59.5, -2.0, CharacteristicPointType.BottomDitchDikeSide); + line.EnsurePointOfType(61.5, -2.0, CharacteristicPointType.BottomDitchPolderSide); + line.EnsurePointOfType(61.5, 0.0, CharacteristicPointType.DitchPolderSide); + line.EnsurePointOfType(75.0, 0.0, CharacteristicPointType.SurfaceLevelInside); + line.Geometry.SyncCalcPoints(); + return line; + } + + } +}