// Copyright (C) Stichting Deltares 2025. 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.Drawing;
using System.Linq;
using Deltares.Dam.Data;
using Deltares.Dam.Data.CsvImporters;
using Deltares.Geometry;
using Deltares.Geotechnics.GeotechnicalGeometry;
using Deltares.Geotechnics.Soils;
using Deltares.Geotechnics.SurfaceLines;
using NUnit.Framework;
namespace Deltares.Dam.Tests;
[TestFixture]
public class DikeTest
{
private Dike dike;
private Segment segment1;
private Location location1;
private SurfaceLine2 surfaceLine1;
private SoilProfile1D soilProfile;
[TearDown]
public void TearDown()
{
dike.Dispose();
}
[SetUp]
public void TestFixtureSetup() {}
[SetUp]
public void TestSetup()
{
// Dike
dike = new Dike();
dike.Name = "Dike";
// Segments
segment1 = new Segment
{
Name = "Segment1"
};
// this.dike.Segments.Add(this.segment1);
// Locations
location1 = new Location();
location1.Name = "Location1";
location1.Segment = segment1;
dike.Locations.Add(location1);
// Surface lines
surfaceLine1 = new SurfaceLine2
{
Geometry = new LocalizedGeometryPointString(),
CharacteristicPoints =
{
GeometryMustContainPoint = true
},
Name = "SurfaceLine1"
};
dike.SurfaceLines2.Add(surfaceLine1);
// Soil profiles
soilProfile = new SoilProfile1D
{
Name = "SoilProfile1"
};
dike.SoilProfiles.Add(soilProfile);
// Locations' Segments
location1.Segment = segment1;
// Locations' surface lines
location1.SurfaceLine2 = surfaceLine1;
// Segments' Soil profile probabilities
segment1.AddSoilProfileProbability(soilProfile, 100.0, FailureMechanismSystemType.StabilityInside);
surfaceLine1.AddCharacteristicPoint(new GeometryPoint(15.3, 0.0, -3.52));
surfaceLine1.AddCharacteristicPoint(new GeometryPoint(19.4, 0.0, -1.46), CharacteristicPointType.DikeToeAtRiver);
surfaceLine1.AddCharacteristicPoint(new GeometryPoint(27.4, 0.0, 8.56), CharacteristicPointType.DikeTopAtRiver);
surfaceLine1.AddCharacteristicPoint(new GeometryPoint(35.2, 0.0, 8.62), CharacteristicPointType.DikeTopAtPolder);
surfaceLine1.AddCharacteristicPoint(new GeometryPoint(41.5, 0.0, -3.76), CharacteristicPointType.DikeToeAtPolder);
surfaceLine1.AddCharacteristicPoint(new GeometryPoint(85.4, 0.0, -3.61));
}
[TearDown]
public void TestTeardown()
{
if (location1 != null)
{
location1.Dispose();
location1 = null;
}
if (surfaceLine1 != null)
{
surfaceLine1.Dispose();
surfaceLine1 = null;
}
}
[Test]
public void DefaultConstructor_ExpectedValues()
{
// setup
// call
using (var newDike = new Dike())
{
// assert
Assert.That(newDike.SurfaceLines2.Count, Is.EqualTo(0));
Assert.That(newDike.Locations.Count, Is.EqualTo(0));
}
}
[Test]
public void TestDikeIntegrity()
{
Assert.That(dike, Is.Not.Null);
Assert.That(dike.Name, Is.EqualTo("Dike"));
//Assert.IsNotNull(this.dike.Segments);
Assert.That(dike.Locations, Is.Not.Null);
Assert.That(dike.SurfaceLines2, Is.Not.Null);
Assert.That(dike.SoilProfiles, Is.Not.Null);
}
// [Test]
// public void TestDikeSegments()
// {
// Assert.IsNotNull(this.segment1);
//
// Assert.AreEqual(1, this.dike.Segments.Count);
// Assert.AreEqual(this.segment1, this.dike.Segments[0]);
// Assert.AreEqual("Segment1", this.segment1.Name);
// Assert.IsNotNull(this.segment1.GetMostProbableProfile(SegmentFailureMechanismType.Stability));
// }
[Test]
public void TestDikeLocations()
{
Assert.That(location1, Is.Not.Null);
Assert.That(dike.Locations.Count, Is.EqualTo(1));
Assert.That(dike.Locations[0], Is.EqualTo(location1));
Assert.That(location1.Name, Is.EqualTo("Location1"));
}
[Test]
public void TestDikeSurfaceLines()
{
Assert.That(surfaceLine1, Is.Not.Null);
Assert.That(surfaceLine1.Geometry.Points, Is.Not.Null);
Assert.That(dike.SurfaceLines2.Count, Is.EqualTo(1));
Assert.That(dike.SurfaceLines2[0], Is.EqualTo(surfaceLine1));
Assert.That(surfaceLine1.Name, Is.EqualTo("SurfaceLine1"));
}
[Test]
public void TestDikeSoilProfiles()
{
Assert.That(soilProfile, Is.Not.Null);
Assert.That(dike.SoilProfiles.Count, Is.EqualTo(1));
Assert.That(dike.SoilProfiles[0], Is.EqualTo(soilProfile));
Assert.That(soilProfile.Name, Is.EqualTo("SoilProfile1"));
}
[Test]
public void TestDikeLocationSegments()
{
Assert.That(location1.Segment, Is.Not.Null);
Assert.That(location1.Segment, Is.EqualTo(segment1));
}
[Test]
public void TestDikeLocationSurfaceLines()
{
Assert.That(location1.SurfaceLine2, Is.Not.Null);
Assert.That(location1.SurfaceLine2, Is.EqualTo(surfaceLine1));
}
[Test]
public void TestDikeSegmentsSoilProfileProbabilities()
{
Assert.That(segment1.GetSoilProfileProbability(soilProfile, FailureMechanismSystemType.StabilityInside), Is.EqualTo(100));
}
[Test]
public void TestDikeSegmentsSurfaceLinePoints()
{
IList points = surfaceLine1.Geometry.Points;
Assert.That(points.Count, Is.EqualTo(6));
Assert.That(points[0].X, Is.EqualTo(15.3));
Assert.That(points[0].Z, Is.EqualTo(-3.52));
Assert.That(points[1].X, Is.EqualTo(19.4));
Assert.That(points[1].Z, Is.EqualTo(-1.46));
Assert.That(surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtRiver), Is.EqualTo(points[1]));
Assert.That(surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtRiver), Is.EqualTo(points[2]));
Assert.That(surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder), Is.EqualTo(points[3]));
Assert.That(surfaceLine1.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder), Is.EqualTo(points[4]));
Assert.That(surfaceLine1.GetCharacteristicPoints(points[0]).Count(cpt => cpt != CharacteristicPointType.None), Is.EqualTo(0));
Assert.That(surfaceLine1.GetCharacteristicPoints(points[1]).First(), Is.EqualTo(CharacteristicPointType.DikeToeAtRiver));
Assert.That(surfaceLine1.HasDike(), Is.True);
}
[Test]
public void TestFillImportedCsvSoilsFromCsvFileWithoutSoilRecords_ThenNoDataBaseSoilsArePresent()
{
var newDike = new Dike();
newDike.FillImportedCsvSoilsFromCsvFile(new List());
Assert.That(newDike.ImportedCsvSoils.Count, Is.Zero);
}
[Test]
public void TestFillImportedCsvSoilsFromCsvFileWithSoilRecords_ThenDataBaseSoilsAreFilled()
{
var newDike = new Dike();
var random = new Random(21);
var soilRecords = new List
{
new()
{
SoilName = "Soil_1",
SoilColor = Color.Black,
SoilType = SoilType.Sand,
SaturatedUnitWeight = random.NextDouble(),
UnsaturatedUnitWeight = random.NextDouble(),
Cohesion = random.NextDouble(),
FrictionAngle = random.NextDouble(),
DiameterD70 = random.NextDouble(),
PermeabilityX = random.NextDouble(),
ShearStrengthModel = ShearStrengthModel.CPhi,
StrengthIncreaseExponent = random.NextDouble(),
RatioSuPc = random.NextDouble(),
Pop = random.NextDouble()
},
new()
{
SoilName = "Soil_2",
SoilColor = Color.White,
SoilType = SoilType.Clay,
SaturatedUnitWeight = random.NextDouble(),
UnsaturatedUnitWeight = random.NextDouble(),
Cohesion = random.NextDouble(),
FrictionAngle = random.NextDouble(),
DiameterD70 = random.NextDouble(),
PermeabilityX = random.NextDouble(),
ShearStrengthModel = ShearStrengthModel.CuCalculated,
StrengthIncreaseExponent = random.NextDouble(),
RatioSuPc = random.NextDouble(),
Pop = random.NextDouble()
}
};
newDike.FillImportedCsvSoilsFromCsvFile(soilRecords);
Assert.That(newDike.ImportedCsvSoils.Count, Is.EqualTo(2));
for (var i = 0; i < newDike.ImportedCsvSoils.Count; i++)
{
Soil soil = newDike.ImportedCsvSoils[i];
CsvImporterSoils.SoilRecord soilRecord = soilRecords[i];
Assert.That(soil.Name, Is.EqualTo(soilRecord.SoilName));
Assert.That(soil.Color, Is.EqualTo(soilRecord.SoilColor));
Assert.That(soil.SoilType, Is.EqualTo(soilRecord.SoilType));
Assert.That(soil.AbovePhreaticLevel, Is.EqualTo(soilRecord.UnsaturatedUnitWeight));
Assert.That(soil.BelowPhreaticLevel, Is.EqualTo(soilRecord.SaturatedUnitWeight));
Assert.That(soil.Cohesion, Is.EqualTo(soilRecord.Cohesion));
Assert.That(soil.FrictionAngle, Is.EqualTo(soilRecord.FrictionAngle));
Assert.That(soil.DiameterD70, Is.EqualTo(soilRecord.DiameterD70));
Assert.That(soil.PermeabKx, Is.EqualTo(soilRecord.PermeabilityX));
Assert.That(soil.ShearStrengthModel, Is.EqualTo(soilRecord.ShearStrengthModel));
Assert.That(soil.StrengthIncreaseExponent, Is.EqualTo(soilRecord.StrengthIncreaseExponent));
Assert.That(soil.RatioCuPc, Is.EqualTo(soilRecord.RatioSuPc));
Assert.That(soil.POP, Is.EqualTo(soilRecord.Pop));
}
}
}