// Copyright (C) Stichting Deltares 2024. 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.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.CurrentScenario = 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.That(messages.Count, Is.EqualTo(0));
// Run the dll
kernelWrapper.Execute(damPipingInput, kernelDataOutput, out messages);
var damPipingOutput = (DamPipingBlighOutput) kernelDataOutput;
Assert.That(messages.Count, Is.EqualTo(0));
Assert.That(damPipingOutput.FoSp, Is.EqualTo(4.5).Within(diff));
Assert.That(damPipingOutput.Hc, Is.EqualTo(2.25).Within(diff));
// Fill the design results
var designScenario = new DesignScenario
{
LocationScenarioID = "1",
LocationName = location.Name
};
List results;
kernelWrapper.PostProcess(damKernelInput, damPipingOutput, designScenario, "", out results);
foreach (DesignResult result in results)
{
Assert.That(result.DamFailureMechanismeCalculation.FailureMechanismSystemType, Is.EqualTo(FailureMechanismSystemType.Piping));
Assert.That(result.DamFailureMechanismeCalculation.PipingModelType, Is.EqualTo(PipingModelType.Bligh));
Assert.That(result.LocationName, Is.Not.Null.Or.Empty);
Assert.That(result.ScenarioName, Is.Not.Null.Or.Empty);
Assert.That(result.ProfileName, Is.Not.Null.Or.Empty);
Assert.That(result.PipingDesignResults.BlighFactor, Is.EqualTo(4.5).Within(diff));
Assert.That(result.PipingDesignResults.BlighHcritical, Is.EqualTo(2.25).Within(diff));
Assert.That(result.PipingDesignResults.LocalExitPointX, Is.EqualTo(50.5));
Assert.That(result.PipingDesignResults.UpliftFactor, Is.EqualTo(0.072811999417504));
Assert.That(result.PipingDesignResults.UpliftSituation != null && ((UpliftSituation)result.PipingDesignResults.UpliftSituation).IsUplift, Is.EqualTo(true));
Assert.That(result.CalculationResult, Is.EqualTo(CalculationResult.Succeeded));
Assert.That(result.PipingDesignResults.RedesignedSurfaceLine, Is.EqualTo(location.SurfaceLine));
}
}
[Test]
public void TestPrepare()
{
const double diff = 0.0001;
var location = new Location();
location.SurfaceLine = FactoryForSurfaceLines.CreateSurfaceLineTutorial1();
location.ModelFactors.UpliftCriterionPiping = 1.0;
location.CurrentScenario = new DesignScenario();
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);
var damPipingInput = (DamPipingBlighInput) kernelDataInput;
Assert.That(damPipingInput.HRiver, Is.EqualTo(2.0).Within(diff));
Assert.That(damPipingInput.HExit, Is.EqualTo(0.0).Within(diff));
Assert.That(damPipingInput.Rc, Is.EqualTo(0.3).Within(diff));
Assert.That(damPipingInput.DTotal, Is.EqualTo(5.0).Within(diff));
Assert.That(damPipingInput.SeepageLength, Is.EqualTo(40.5).Within(diff));
Assert.That(damPipingInput.D70, Is.EqualTo(180.0).Within(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.That(messages.Count, Is.GreaterThan(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.That(messages.Count, Is.EqualTo(0));
}
[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;
var 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",
LocationName = "nieuw"
};
List results;
kernelWrapper.PostProcess(input, output, designScenario, "", out results);
foreach (DesignResult result in results)
{
Assert.That(result.PipingDesignResults.BlighFactor, Is.EqualTo(output.FoSp));
Assert.That(result.PipingDesignResults.BlighHcritical, Is.EqualTo(output.Hc));
Assert.That(result.PipingDesignResults.LocalExitPointX, Is.EqualTo(output.ExitPointX));
Assert.That(result.PipingDesignResults.UpliftFactor, Is.EqualTo(output.UpliftFactor));
Assert.That(result.PipingDesignResults.UpliftSituation, Is.EqualTo(output.UpliftSituation));
Assert.That(result.CalculationResult, Is.EqualTo(output.CalculationResult));
Assert.That(result.PipingDesignResults.RedesignedSurfaceLine, Is.EqualTo(input.Location.SurfaceLine));
}
}
[Test]
[SetUICulture("nl-NL")]
public void TestLanguageNLThrowsExceptionInExecuteWhenInputIsNull()
{
var kernelWrapper = new DamPipingBlighKernelWrapper();
List messages;
Assert.That(() => kernelWrapper.Execute(null, null, out messages), Throws.InstanceOf().With.Message.EqualTo("Geen invoer object gedefinieerd voor Bligh"));
}
[Test]
[SetUICulture("en-US")]
public void TestLanguageENThrowsExceptionInExecuteWhenInputIsNull()
{
var kernelWrapper = new DamPipingBlighKernelWrapper();
List messages;
Assert.That(() => kernelWrapper.Execute(null, null, out messages), Throws.InstanceOf().With.Message.EqualTo("No input object defined for Bligh"));
}
[Test]
[SetUICulture("nl-NL")]
public void TestThrowsExceptionInPostProcessWhenOutputIsNull()
{
var kernelWrapper = new DamPipingBlighKernelWrapper();
List results;
Assert.That(() => kernelWrapper.PostProcess(new DamKernelInput(), null, null, "", out results), Throws.InstanceOf().With.Message.EqualTo("Geen uitvoer object gedefinieerd voor Bligh"));
}
[Test]
[SetUICulture("nl-NL")]
public void TestThrowsExceptionInPostProcessWhenInputIsNull()
{
var kernelWrapper = new DamPipingBlighKernelWrapper();
List results;
Assert.That(() => kernelWrapper.PostProcess(null, new DamPipingBlighOutput(), null, "", out results), Throws.InstanceOf().With.Message.EqualTo("Geen Dam invoer object gedefinieerd voor Bligh"));
}
}