// 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.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 NUnit.Framework;
using Deltares.DamEngine.Calculators.KernelWrappers.DamPipingSellmeijerVnk;
using Deltares.DamEngine.TestHelpers.Factories;
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
// FoSbe = Hcbe / reducedFall = 3.65 / 1.0 = 3.65
// Hcbe is calculated with external dll
const double diff = 0.01;
var location = new Location("Location 1")
{
SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(),
ModelFactors =
{
UpliftCriterionPiping = 1.0
}
};
location.Scenarios.Add(new DesignScenario());
var designScenario = new DesignScenario
{
LocationScenarioID = "1",
Location = location,
ModelFactors =
{
UpliftCriterionPiping = 1.0
}
};
var subSoilScenario = new SoilGeometryProbability();
subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithTwoSandlayers();
subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping;
var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification()
{
FailureMechanismSystemType = FailureMechanismSystemType.Piping,
PipingModelType = PipingModelType.SellmeijerVnk
};
var damKernelInput = new DamKernelInput
{
Location = location,
SubSoilScenario = subSoilScenario,
RiverLevelHigh = 1.0,
DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification
};
var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper();
// 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);
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
List results;
kernelWrapper.PostProcess(damKernelInput, damPipingOutput, designScenario, "", out results);
foreach (var result in results)
{
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);
Assert.AreEqual(50.5, result.PipingDesignResults.LocalExitPointX);
Assert.AreEqual(0.067957866123003738, 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.000001;
var designScenario = new DesignScenario();
designScenario.Location = new Location();
designScenario.ModelFactors.UpliftCriterionPiping = 1.0;
var location = new Location
{
SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(),
ModelFactors =
{
UpliftCriterionPiping = 1.0
}
};
location.Scenarios.Add(new DesignScenario());
var subSoilScenario = new SoilGeometryProbability();
subSoilScenario.SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithTwoSandlayers();
subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping;
var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification()
{
FailureMechanismSystemType = FailureMechanismSystemType.Piping,
PipingModelType = PipingModelType.SellmeijerVnk
};
var damKernelInput = new DamKernelInput
{
Location = location,
SubSoilScenario = subSoilScenario,
RiverLevelHigh = 1.0,
DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification
};
var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper();
IKernelDataInput kernelDataInput;
IKernelDataOutput kernelDataOutput;
kernelWrapper.Prepare(damKernelInput, 0, 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(1.99, 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 = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithTwoSandlayers();
subSoilScenario.SegmentFailureMechanismType = SegmentFailureMechanismType.Piping;
var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification()
{
FailureMechanismSystemType = FailureMechanismSystemType.Piping,
PipingModelType = PipingModelType.SellmeijerVnk
};
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;
DamPipingSellmeijerVnkOutput output = new DamPipingSellmeijerVnkOutput
{
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.SellmeijerVnkFactor);
Assert.AreEqual(output.Hc, result.PipingDesignResults.SellmeijerVnkHcritical);
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 VNK")]
[SetUICulture("nl-NL")]
public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull()
{
var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper();
List messages;
kernelWrapper.Execute(null, null, out messages);
}
[Test]
[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]
[ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen uitvoer object gedefinieerd voor Sellmeijer VNK")]
[SetUICulture("nl-NL")]
public void TestThrowsExceptionInPostProcessWhenOutputIsNull()
{
var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper();
List results;
kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out results);
}
[Test]
[ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen invoer object gedefinieerd voor Sellmeijer VNK")]
[SetUICulture("nl-NL")]
public void TestThrowsExceptionInPostProcessWhenInputIsNull()
{
var kernelWrapper = new DamPipingSellmeijerVnkKernelWrapper();
List results;
kernelWrapper.PostProcess(null, new DamPipingSellmeijerVnkOutput(), null, "", out results);
}
}
}