// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU 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.IO;
using Deltares.Dam.Data;
using Deltares.Dam.Data.DamEngineIo;
using NUnit.Framework;
using Deltares.Dam.TestHelper;
using Deltares.DamEngine.Interface;
using Deltares.DamEngine.Io;
using Deltares.Standard.TestUtils;
namespace Deltares.Dam.Tests
{
[TestFixture]
public class DamPipingBenchmarkTest
{
const double cTolerance = 0.0005;
///
/// Compute project
///
///
///
private static List ComputeProject(string projectFilename, PipingModelType pipingModel)
{
// Read dikering
using (var damProjectData = ProjectLoader.LoadProjectData(projectFilename))
{
Assert.AreEqual(1, damProjectData.WaterBoard.Dikes.Count);
var dike = damProjectData.WaterBoard.Dikes[0];
Assert.AreEqual(1, dike.Locations.Count);
damProjectData.DamProjectCalculationSpecification.CurrentSpecification.PipingModelType = pipingModel;
DamEngine.Io.XmlInput.Input input = FillXmlInputFromDamUi.CreateInput(damProjectData);
string inputXml = DamXmlSerialization.SaveInputAsXmlString(input);
var damEnginInterface = new EngineInterface(inputXml);
string validationMessages = damEnginInterface.Validate();
if (string.IsNullOrEmpty(validationMessages))
{
// only if validation is ok, then
string outputXml = damEnginInterface.Run();
var output = DamXmlSerialization.LoadOutputFromXmlString(outputXml);
FillDamUiFromXmlOutput.AddOutputToDamProjectData(damProjectData, output);
}
var allCalculationresults = damProjectData.DesignCalculations;
return allCalculationresults;
}
}
///
/// Benchmark test 1
///
[Test]
public void Bm01OneAquiferOneLayer()
{
string projectFilename = @"..\..\..\data\Dam\Benchmarks\Piping\Test 1\Integratietest piping 1.damx";
var allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer4Forces);
double expectedPipingFactor = 0.506; // This is calculated according to spreadsheet
double expectedHCritical = 1.618839023; // This is calculated according to spreadsheet
double expectedLocalPipingExitPointX = 35; // This is just taken from the calculation result itself
double expectedPl3HeadAdjusted = 0.0; // For Piping, this must always be 0
double expectedPl4HeadAdjusted = 0.0; // For Piping, this must always be 0
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer4ForcesPipingFactor.Value, cTolerance);
Assert.AreEqual(expectedHCritical, allCalculationresults[0].Sellmeijer4ForcesHCritical.Value, cTolerance);
Assert.AreEqual(true, allCalculationresults[0].IsUplift.Value);
Assert.AreEqual(expectedLocalPipingExitPointX, allCalculationresults[0].LocalPipingExitPointX.Value, cTolerance);
Assert.AreEqual(expectedPl3HeadAdjusted, allCalculationresults[0].Pl3HeadAdjusted.Value, cTolerance);
Assert.AreEqual(expectedPl4HeadAdjusted, allCalculationresults[0].Pl4HeadAdjusted.Value, cTolerance);
// Sellmeijer2Forces NOT supported for now
//expectedPipingFactor = 0.3774; // This is just taken from the calculation result itself
//Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer2ForcesPipingFactor.Value, cTolerance);
allCalculationresults.Clear();
allCalculationresults = ComputeProject(projectFilename, PipingModelType.Bligh);
expectedPipingFactor = 0.5208; // This is just taken from the calculation result itself
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].BlighPipingFactor.Value, cTolerance);
// Wti2017 NOT supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Wti2017);
// expectedPipingFactor = 0.36395601533789024; // This is just taken from the calculation result itself
// expectedHCritical = 1.3830328582839828; // This is just taken from the calculation result itself
// expectedLocalPipingExitPointX = 35; // This is just taken from the calculation result itself
// expectedPl3HeadAdjusted = 0.0; // This is just taken from the calculation result itself
// expectedPl4HeadAdjusted = 0.0; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Wti2017PipingFactor.Value, cTolerance);
// Assert.AreEqual(expectedHCritical, allCalculationresults[0].Wti2017HCritical.Value, cTolerance);
// Assert.AreEqual(true, allCalculationresults[0].IsUplift.Value);
// Assert.AreEqual(expectedLocalPipingExitPointX, allCalculationresults[0].LocalPipingExitPointX.Value, cTolerance);
//Assert.AreEqual(expectedPl3HeadAdjusted, allCalculationresults[0][0].Pl3HeadAdjusted.Value, cTolerance);
//Assert.AreEqual(expectedPl4HeadAdjusted, allCalculationresults[0][0].Pl4HeadAdjusted.Value, cTolerance);
}
///
/// Benchmark test 2
///
[Test]
public void Bm02OneAquiferTwoLayers()
{
string projectFilename = @"..\..\..\data\Dam\Benchmarks\Piping\Test 2\Integratietest piping 2.damx";
var allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer4Forces);
double expectedPipingFactor = 0.489; // This is calculated according to spreadsheet
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer4ForcesPipingFactor.Value, cTolerance);
// Sellmeijer2Forces is NOT supported for now
//allCalculationresults.Clear();
//allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer2Forces);
//expectedPipingFactor = 0.3688; // This is just taken from the calculation result itself
//Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer2ForcesPipingFactor.Value, cTolerance);
allCalculationresults.Clear();
allCalculationresults = ComputeProject(projectFilename, PipingModelType.Bligh);
expectedPipingFactor = 0.5208; // This is just taken from the calculation result itself
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].BlighPipingFactor.Value, cTolerance);
// Wti2017 is not supported for now
//allCalculationresults.Clear();
//allCalculationresults = ComputeProject(projectFilename, PipingModelType.Wti2017);
//expectedPipingFactor = 0.35572120356770748; // This is just taken from the calculation result itself
//Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Wti2017PipingFactor.Value, cTolerance);
}
///
/// Benchmark test 3
///
[Test]
public void Bm03OneAquiferThreeLayers()
{
string projectFilename = @"..\..\..\data\Dam\Benchmarks\Piping\Test 3\Integratietest piping 3.damx";
var allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer4Forces);
double expectedPipingFactor = 0.494; // This is calculated according to spreadsheet
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer4ForcesPipingFactor.Value, cTolerance);
// Sellmeijer2Forces is NOT supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer2Forces);
// expectedPipingFactor = 0.3733; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer2ForcesPipingFactor.Value, cTolerance);
allCalculationresults.Clear();
allCalculationresults = ComputeProject(projectFilename, PipingModelType.Bligh);
expectedPipingFactor = 0.5208; // This is just taken from the calculation result itself
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].BlighPipingFactor.Value, cTolerance);
// Wti2017 is not supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Wti2017);
// expectedPipingFactor = 0.36005969460534598; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Wti2017PipingFactor.Value, cTolerance);
}
///
/// Benchmark test 4
///
[Test]
public void Bm04TwoAquifersOneLayer()
{
string projectFilename = @"..\..\..\data\Dam\Benchmarks\Piping\Test 4\Integratietest piping 4.damx";
var allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer4Forces);
double expectedPipingFactor = 0.608; // This is calculated according to spreadsheet
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer4ForcesPipingFactor.Value, cTolerance);
// Sellmeijer2Forces is NOT supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer2Forces);
// expectedPipingFactor = 0.4410; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer2ForcesPipingFactor.Value, cTolerance);
allCalculationresults.Clear();
allCalculationresults = ComputeProject(projectFilename, PipingModelType.Bligh);
expectedPipingFactor = 0.5208; // This is just taken from the calculation result itself
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].BlighPipingFactor.Value, cTolerance);
// Wti2017 is not supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Wti2017);
// expectedPipingFactor = 0.42527879109125538; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Wti2017PipingFactor.Value, cTolerance);
}
///
/// Benchmark test 5
///
[Test]
public void Bm05TwoAquifersTwoLayers()
{
string projectFilename = @"..\..\..\data\Dam\Benchmarks\Piping\Test 5\Integratietest piping 5.damx";
var allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer4Forces);
double expectedPipingFactor = 0.618; // This is calculated according to spreadsheet
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer4ForcesPipingFactor.Value, cTolerance);
// Sellmeijer2Forces is NOT supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Sellmeijer2Forces);
// expectedPipingFactor = 0.4494; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Sellmeijer2ForcesPipingFactor.Value, cTolerance);
allCalculationresults.Clear();
allCalculationresults = ComputeProject(projectFilename, PipingModelType.Bligh);
expectedPipingFactor = 0.5208; // This is just taken from the calculation result itself
Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].BlighPipingFactor.Value, cTolerance);
// Wti2017 is not supported for now
// allCalculationresults.Clear();
// allCalculationresults = ComputeProject(projectFilename, PipingModelType.Wti2017);
// expectedPipingFactor = 0.43345922746899618; // This is just taken from the calculation result itself
// Assert.AreEqual(expectedPipingFactor, allCalculationresults[0].Wti2017PipingFactor.Value, cTolerance);
}
}
}