// Copyright (C) Stichting Deltares 2023. 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.IO;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Data.Standard.Calculation;
using Deltares.DamEngine.Interface;
using Deltares.DamEngine.Io;
using Deltares.DamEngine.Io.XmlOutput;
using Deltares.DamEngine.TestHelpers;
using NUnit.Framework;
using ConversionHelper = Deltares.DamEngine.Interface.ConversionHelper;
namespace Deltares.DamEngine.IntegrationTests.IntegrationTests;
[TestFixture]
public class PipingSellmeijerVnkTests
{
private const double tolerance = 0.0005;
private const string workingDir = @"TestFiles\";
private string oldWorkingDir;
[SetUp]
public void TestFixtureSetup()
{
oldWorkingDir = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(workingDir);
}
[TearDown]
public void TestFixtureTearDown()
{
Directory.SetCurrentDirectory(oldWorkingDir);
}
/// Test for different segmentFailureMechanismType
/// The soilprobabilities are set tot the specified segmentFailureMechanismType
[Test]
[TestCase(ConversionHelper.InputSegmentFailureMechanismPiping)]
[TestCase(ConversionHelper.InputSegmentFailureMechanismAll)]
public void CanPerformSellmeijerVnkDesignPipingVoorbeeld1(int segmentFailureMechanismType)
{
// Based on ".\data\DamEngineTestProjects\PipingVoorbeeld1\PipingVoorbeeld1.damx"
// Select Failure mechanism Piping and model Sellmeijer (VNK)
// Set Analysis type to "No Adaption"
const string fileName = @"PipingVoorbeeld1_SellmeijerVNKInputFile.xml";
string inputString = File.ReadAllText(fileName);
inputString = XmlAdapter.ChangeValueInXml(inputString, "SegmentFailureMechanismType", segmentFailureMechanismType.ToString());
var engineInterface = new EngineInterface(inputString);
Assert.IsNotNull(engineInterface.DamProjectData);
string outputString = engineInterface.Run();
// Factor piping = 0.463
// Kritische hoogte = 1.619
// Factor opdrijven = 0.351
// Kwelweglengte piping = 25.0
// Intredepunt x-lokaal = 10.0
// Uittredepunt x-lokaal = 35.0
// Opdrijven = true
// Profielnaam = soilprofile_01
// PL3 opdrijven = 0.582
// PL3 stijghoogte aangepast = 1.262
// PL3 locatie opdriven lokaal = 35.0
// PL4 opdrijven = 0.0
// PL4 stijghoogte aangepast = 0.0
// PL4 locatie opdrijven lokaal = 0.0
// Locatie naam = "profiel 1"
// ID locatie scenario = "1"
// Heave Factor = 90.0
Assert.IsNotNull(outputString);
Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString);
Assert.IsNotNull(output.Results.CalculationResults, "No results available");
Assert.AreEqual(0.463, output.Results.CalculationResults[0].PipingDesignResults.SellmeijerVnkFactor, tolerance);
Assert.AreEqual(1.759, output.Results.CalculationResults[0].PipingDesignResults.SellmeijerVnkHcritical, tolerance);
Assert.AreEqual(35.0, output.Results.CalculationResults[0].PipingDesignResults.ExitPointX, tolerance);
// The following values are not the same as in the classic UI
// The upliftfactor there is 0.351, but that is the Wti Upliftfactor
// The adjusted PL3/PL4 values there are not 0.0, but those are the values for stability; for piping no adjustment has to be made
Assert.AreEqual(0.5825, output.Results.CalculationResults[0].PipingDesignResults.UpliftFactor, tolerance);
Assert.AreEqual(true, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.IsUplift);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl3MinUplift, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl3HeadAdjusted, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl3LocationXMinUplift, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl4MinUplift, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl4HeadAdjusted, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl4LocationXMinUplift, tolerance);
}
[Test]
public void CanPerformSellmeijerVnkDesignWithAdaptionPipingVoorbeeld1()
{
// Based on ".\data\DamEngineTestProjects\PipingVoorbeeld1\PipingVoorbeeld1.damx"
// Select Failure mechanism Piping and model Sellmeijer (VNK)
// Set Analysis type to "Adapt geometry"
// Change required safety factor piping to 1.01
const string fileName = @"PipingVoorbeeld1_SellmeijerVNKDesignInputFile.xml";
string inputString = File.ReadAllText(fileName);
var engineInterface = new EngineInterface(inputString);
Assert.IsNotNull(engineInterface.DamProjectData);
string outputString = engineInterface.Run();
Assert.IsNotNull(outputString);
Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString);
DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(null, output);
SurfaceLine2 redesignedSurfaceLine = actualDamProjectData.DesignCalculations[0].PipingDesignResults.RedesignedSurfaceLine;
// uplift = true
Assert.AreEqual(true, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.IsUplift);
// shoulder height = 1.995
Assert.AreEqual(1.995, redesignedSurfaceLine.DetermineShoulderHeight(), tolerance);
// dike length = 84.486
Assert.That(redesignedSurfaceLine.GetDikeLength(), Is.EqualTo(84.486).Within(tolerance));
// ShoulderLength = X_Kruin binnenberm - X_Insteek binnenberm = 82.51 - 29.01 = 53.5
// Read from PipingSellmeijerVNK_Piping_CharacteristicPoints.csv by export surfacelines in Release
Assert.AreEqual(53.5, redesignedSurfaceLine.DetermineShoulderLength(), tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl3MinUplift, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl3HeadAdjusted, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl3LocationXMinUplift, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl4MinUplift, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl4HeadAdjusted, tolerance);
Assert.AreEqual(0.0, output.Results.CalculationResults[0].PipingDesignResults.UpliftSituation.Pl4LocationXMinUplift, tolerance);
// The ExitPointX in Dam 15.1.2.24738 is (incorrectly) not shown
// ExitPointX = X_Teen dijk binnenwaarts = 94.486
// Read from PipingSellmeijerVNK_Piping_CharacteristicPoints.csv by export surfacelines in Release
Assert.AreEqual(94.486, output.Results.CalculationResults[0].PipingDesignResults.ExitPointX, tolerance);
// The following values are not the same as in the Dam 15.1.2.24738 release
// The final piping calculation at the redesigned situation is done at X = 29.014 (the "insteek van de berm"),
// but it should have been done at X = 94.486 (the "teen van de dijk")
// Found expected values by debugging with Classic
// after change in Classic: upliftLocationDeterminator.GetLocationAndResult(upliftcriterion - 0.000000001)
// The Factor in Dam 15.1.2.24738 is 1.167, but that is not correct, because that is the value at X = 29.014
// expected value = 1.070
Assert.AreEqual(1.070, output.Results.CalculationResults[0].PipingDesignResults.SellmeijerVnkFactor, tolerance);
// The Hcritical in Dam 15.1.2.24738 is 2.105, but that is not correct, because that is the value at X = 29.014
// expected value = 4.067
Assert.AreEqual(4.067, output.Results.CalculationResults[0].PipingDesignResults.SellmeijerVnkHcritical, tolerance);
// The upliftfactor in Dam 15.1.2.24738 is (incorrectly) not shown
// expected value = 0.582
Assert.AreEqual(0.582, output.Results.CalculationResults[0].PipingDesignResults.UpliftFactor, tolerance);
}
[Test]
public void TestIfSellmeijerVnkCalculationResultIsSetToFailDueToShoulderShoulderLengthError()
{
// Based on ".\data\DamEngineTestProjects\PipingVoorbeeld1\PipingVoorbeeld1.damx"
// Select Failure mechanism Piping and model Sellmeijer (VNK)
// Set Analysis type to "Adapt geometry"
const string fileName = @"PipingVoorbeeld1_SellmeijerVNKDesignInputFileFail.xml";
string inputString = File.ReadAllText(fileName);
var engineInterface = new EngineInterface(inputString);
Assert.IsNotNull(engineInterface.DamProjectData);
string outputString = engineInterface.Run();
Assert.IsNotNull(outputString);
Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString);
Assert.AreEqual(CalculationResult.RunFailed, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults[0].CalculationResult));
// expected value = -1 because exception was raised for the shoulder length
Assert.AreEqual(-1.0, output.Results.CalculationResults[0].PipingDesignResults.SellmeijerVnkFactor, tolerance);
Assert.AreEqual("The new shoulder length is too large to fit in the current surface line.",
output.Results.CalculationResults[0].PipingDesignResults.ResultMessage);
Assert.AreEqual("Location 'Profiel 1', subsoil scenario 'soilprofile_01', design scenario '1': " +
"The calculation failed with error message " +
"'The design was not successful. " +
"The new shoulder length is too large to fit in the current surface line.'",
output.Results.CalculationMessages[0].Message1);
}
[Test]
public void TestIfSellmeijerVnkCalculationGeneratesNoErrorWhenNewShoulderLengthIsSmaller()
{
// Based on ".\data\DamEngineTestProjects\Invoer3\DeltaDijk\DeltaDijk normal.damx"
// Select Failure mechanism Piping and model Sellmeijer (VNK)
// Set Analysis type to "Adapt geometry"
const string fileName = @"DeltaDijkInvoer3VNKAdaptionShoulderLength.xml";
string inputString = File.ReadAllText(fileName);
var engineInterface = new EngineInterface(inputString);
Assert.IsNotNull(engineInterface.DamProjectData);
string outputString = engineInterface.Run();
Assert.IsNotNull(outputString);
Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString);
Assert.AreEqual(CalculationResult.Succeeded, ConversionHelper.ConvertToCalculationResult(output.Results.CalculationResults[0].CalculationResult));
Assert.AreEqual(true, output.Results.CalculationResults[0].PipingDesignResults.SellmeijerVnkFactor > -1);
Assert.AreEqual("", output.Results.CalculationResults[0].PipingDesignResults.ResultMessage);
}
}