// 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.Linq;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.TestHelpers.Factories;
using KellermanSoftware.CompareNetObjects;
using NUnit.Framework;
namespace Deltares.DamEngine.Data.Tests.Geotechnics;
[TestFixture]
public class SoilProfile2DTests
{
private double precison10Decimals = 0.000000000051;
[Test]
public void GivenProfile2DWhenCloningThenClonedProfile2DEqualsOriginal()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
soilProfile2D.Surfaces.Last().IsAquifer = true;
soilProfile2D.Surfaces.Last().WaterpressureInterpolationModel = WaterpressureInterpolationModel.Hydrostatic;
soilProfile2D.Name = "";
var preConsolidationStress = new PreConsolidationStress
{
Name = "Preconsolidation stress name",
StressValue = 1.234,
X = 12.34,
Z = 56.78
};
soilProfile2D.PreconsolidationStresses.Add(preConsolidationStress);
// When
SoilProfile2D cloneSoilProfile2D = soilProfile2D.Clone();
// Then
CompareSoilProfile2D(soilProfile2D, cloneSoilProfile2D);
}
[Test]
public void GivenProfile2DWhenCloningThenPointsAreReferences()
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithThreeLayers();
soilProfile2D.Surfaces.Last().IsAquifer = true;
soilProfile2D.Surfaces.Last().WaterpressureInterpolationModel = WaterpressureInterpolationModel.Hydrostatic;
soilProfile2D.Name = "";
var preConsolidationStress = new PreConsolidationStress
{
Name = "Preconsolidation stress name",
StressValue = 1.234,
X = 12.34,
Z = 56.78
};
soilProfile2D.PreconsolidationStresses.Add(preConsolidationStress);
// When
SoilProfile2D cloneSoilProfile2D = soilProfile2D.Clone();
cloneSoilProfile2D.Geometry.Points.First().X = -99.99;
soilProfile2D.Geometry.Points.First().X = -7.77;
Assert.Multiple(() =>
{
// Then
Assert.That(soilProfile2D.Geometry.Points.First().X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Geometry.Curves[0].HeadPoint.X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Geometry.Curves[5].EndPoint.X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Geometry.Loops[0].Points[0].X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Geometry.Surfaces[0].OuterLoop.Points[0].X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Geometry.Surfaces[0].OuterLoop.CurveList[0].HeadPoint.X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Geometry.Curves[0].SurfaceAtRight.OuterLoop.Points[0].X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Surfaces[0].GeometrySurface.OuterLoop.Points[0].X, Is.EqualTo(-7.77));
Assert.That(soilProfile2D.Surfaces[0].GeometrySurface.OuterLoop.CurveList[0].HeadPoint.X, Is.EqualTo(-7.77));
Assert.That(cloneSoilProfile2D.Geometry.Points.First().X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Geometry.Curves[0].HeadPoint.X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Geometry.Curves[5].EndPoint.X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Geometry.Loops[0].Points[0].X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Geometry.Loops[0].CurveList[0].HeadPoint.X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Geometry.Surfaces[0].OuterLoop.Points[0].X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Geometry.Curves[0].SurfaceAtRight, Is.EqualTo(null));
Assert.That(cloneSoilProfile2D.Geometry.Curves[0].SurfaceAtLeft, Is.EqualTo(null));
Assert.That(cloneSoilProfile2D.Surfaces[0].GeometrySurface.OuterLoop.Points[0].X, Is.EqualTo(-99.99));
Assert.That(cloneSoilProfile2D.Surfaces[0].GeometrySurface.OuterLoop.CurveList[0].HeadPoint.X, Is.EqualTo(-99.99));
});
}
[Test]
[TestCase( true, -20.000, -20.000)]
[TestCase( false, -20.000, -19.997)]
[TestCase( true, -50.000, -49.999)]
[TestCase( true, -10.000, -10.001)]
public void GivenProfile2DWithVerticalSeparationLayerWhenDeterminingSoilProfile1DAtSeparationThenReturnsExpectedSoilProfile1D(bool areConsecutiveSoilsIdentical, double givenX, double expectedX)
{
// Given
SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithFourSurfacesAndThreeVerticalSeparationDistantFrom1Mm(areConsecutiveSoilsIdentical);
soilProfile2D.Name = "Soil Profile 2D Test";
// When
SoilProfile1D soilProfile1D = soilProfile2D.GetSoilProfile1D(givenX);
// Then
Assert.That(soilProfile1D.Layers, Has.Count.EqualTo(2));
Assert.Multiple(() =>
{
Assert.That(soilProfile1D.Layers[0].TopLevel, Is.EqualTo(10).Within(precison10Decimals));
Assert.That(soilProfile1D.Layers[1].TopLevel, Is.EqualTo(0).Within(precison10Decimals));
Assert.That(soilProfile1D.BottomLevel, Is.EqualTo(-15).Within(precison10Decimals));
Assert.That(soilProfile1D.Name, Is.EqualTo("Generated at x = " + expectedX.ToString("F3") + " from Soil Profile 2D Test"));
if (areConsecutiveSoilsIdentical)
{
Assert.That(soilProfile1D.Layers[0].Soil.Name, Is.EqualTo("Soil1"));
Assert.That(soilProfile1D.Layers[1].Soil.Name, Is.EqualTo("Soil5"));
}
else
{
Assert.That(soilProfile1D.Layers[0].Soil.Name, Is.EqualTo("Soil4"));
Assert.That(soilProfile1D.Layers[1].Soil.Name, Is.EqualTo("Soil7"));
}
});
}
private static void CompareSoilProfile2D(SoilProfile2D sourceSoilProfile2D, SoilProfile2D targetSoilProfile2D)
{
Assert.That(targetSoilProfile2D, Is.Not.SameAs(sourceSoilProfile2D));
var compare = new CompareLogic
{
Config =
{
MaxDifferences = 100
}
};
compare.Config.MembersToIgnore = new List
{
"SurfaceAtRight",
"SurfaceAtLeft"
};
ComparisonResult result = compare.Compare(sourceSoilProfile2D, targetSoilProfile2D);
Assert.That(result.Differences, Is.Empty, "Differences found read/write Input object");
}
}