// Copyright (C) Stichting Deltares 2018. 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.Calculators.KernelWrappers.WbiPipingSellmeijerRevised;
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.WbiPipingSellmeijerRevised
{
[TestFixture]
public class WbiPipingSellmeijerRevisedKernelWrapperTests
{
[Test]
public void TestFullCalculation()
{
// expected results are based on test in Sellmeijer2011CalculatorTests, CalculateTestValues
// as performed in the Wti kernel itself.
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
{
SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithOneSandlayer(),
SegmentFailureMechanismType = FailureMechanismSystemType.Piping
};
var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification()
{
FailureMechanismSystemType = FailureMechanismSystemType.Piping,
PipingModelType = PipingModelType.Wti2017
};
var damKernelInput = new DamKernelInput
{
Location = location,
SubSoilScenario = subSoilScenario,
RiverLevelHigh = 1.0,
DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification
};
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
// Prepare the wrapper. Result is input for the calculation dll
IKernelDataInput damPipingInput;
IKernelDataOutput kernelDataOutput;
kernelWrapper.Prepare(damKernelInput, 0, out damPipingInput, out kernelDataOutput);
// Original test in piping kernel uses the corrected D70 so use that here too
(damPipingInput as WbiPipingSellmeijerRevisedInput).D70 = (damPipingInput as WbiPipingSellmeijerRevisedInput).D70 * 1e6;
// 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);
var damPipingOutput = (WbiPipingSellmeijerRevisedOutput)kernelDataOutput;
Assert.AreEqual(0, messages.Count);
Assert.AreEqual(2719.6685415725829, damPipingOutput.FoSp, diff);
Assert.AreEqual(1087.8674166290334, 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.Wti2017, result.DamFailureMechanismeCalculation.PipingModelType);
Assert.IsNotNullOrEmpty(result.LocationName);
Assert.IsNotNullOrEmpty(result.ScenarioName);
Assert.IsNotNullOrEmpty(result.ProfileName);
Assert.AreEqual(90, result.PipingDesignResults.Wti2017Factor, diff);
Assert.AreEqual(1087.8674166290334, result.PipingDesignResults.Wti2017Hcritical, 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.0001;
var location = new Location
{
SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1(),
ModelFactors =
{
UpliftCriterionPiping = 1.0
}
};
var subSoilScenario = new SoilGeometryProbability
{
SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithOneSandlayer(),
SegmentFailureMechanismType = FailureMechanismSystemType.Piping
};
var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification()
{
FailureMechanismSystemType = FailureMechanismSystemType.Piping,
PipingModelType = PipingModelType.Wti2017
};
var damKernelInput = new DamKernelInput
{
Location = location,
SubSoilScenario = subSoilScenario,
RiverLevelHigh = 1.0,
DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification
};
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
IKernelDataInput kernelDataInput;
IKernelDataOutput kernelDataOutput;
kernelWrapper.Prepare(damKernelInput, 0, out kernelDataInput, out kernelDataOutput);
var damPipingInput = (WbiPipingSellmeijerRevisedInput)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.DAquifer, diff);
Assert.AreEqual(40.5, damPipingInput.SeepageLength, diff);
Assert.AreEqual(0.000200, damPipingInput.D70, diff);
Assert.AreEqual(0.25, damPipingInput.WhitesDragCoefficient, diff);
Assert.AreEqual(37.0, damPipingInput.BeddingAngle, diff);
Assert.AreEqual(1.33E-06, damPipingInput.KinematicViscosityWater, diff);
Assert.AreEqual(0.0001, damPipingInput.DarcyPermeability, diff);
}
[Test]
public void TestValidate()
{
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
// Validate without setting values. Expected error messages.
var damPipingInput = new WbiPipingSellmeijerRevisedInput();
var damPipingOutput = new WbiPipingSellmeijerRevisedOutput();
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 WbiPipingSellmeijerRevisedInput()
{
HRiver = 1.0,
HExit = 0.0,
Rc = 0.3,
DTotal = 2.0,
DAquifer = 8.0,
SeepageLength = 40.5,
D70 = 200.0,
WhitesDragCoefficient = 0.25,
BeddingAngle = 37.0,
KinematicViscosityWater = 1.33E-06,
DarcyPermeability = 0.0001
};
messages.Clear();
kernelWrapper.Validate(damPipingInput, damPipingOutput, out messages);
Assert.AreEqual(0, messages.Count);
}
[Test]
public void TestPostProcess()
{
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
var subSoilScenario = new SoilGeometryProbability
{
SoilProfile1D = FactoryForSoilProfiles.CreatePipingSellmeijerProfileWithOneSandlayer(),
SegmentFailureMechanismType = FailureMechanismSystemType.Piping
};
var damFailureMechanismeCalculationSpecification = new DamFailureMechanismeCalculationSpecification()
{
FailureMechanismSystemType = FailureMechanismSystemType.Piping,
PipingModelType = PipingModelType.Wti2017
};
var input = new DamKernelInput
{
Location = new Location(),
SubSoilScenario = subSoilScenario,
DamFailureMechanismeCalculationSpecification = damFailureMechanismeCalculationSpecification
};
input.Location = new Location();
var upliftSituation = new UpliftSituation
{
IsUplift = true
};
var calculationResult = CalculationResult.Succeeded;
var output = new WbiPipingSellmeijerRevisedOutput()
{
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.Wti2017Factor);
Assert.AreEqual(output.Hc, result.PipingDesignResults.Wti2017Hcritical);
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 WBI Sellmeijer Revised")]
[SetUICulture("nl-NL")]
public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull()
{
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
List messages;
kernelWrapper.Execute(null, null, out messages);
}
[Test]
[ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "No input object defined for WBI Sellmeijer Revised")]
[SetUICulture("en-US")]
public void TestLanguageENThrowsExceptionInExecuteWhenInputIsNull()
{
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
List messages;
kernelWrapper.Execute(null, null, out messages);
}
[Test]
[ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen uitvoer object gedefinieerd voor WBI Sellmeijer Revised")]
[SetUICulture("nl-NL")]
public void TestThrowsExceptionInPostProcessWhenOutputIsNull()
{
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
List results;
kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out results);
}
[Test]
[ExpectedException(typeof(NoNullAllowedException), ExpectedMessage = "Geen invoer object gedefinieerd voor WBI Sellmeijer Revised")]
[SetUICulture("nl-NL")]
public void TestThrowsExceptionInPostProcessWhenInputIsNull()
{
var kernelWrapper = new WbiPipingSellmeijerRevisedKernelWrapper();
List results;
kernelWrapper.PostProcess(null, new DamPipingSellmeijer4ForcesOutput(), null, "", out results);
}
}
}