using System; using System.IO; using System.Linq; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using Deltares.Geotechnics.TestUtils; using Deltares.Standard.IO.Xml; using Deltares.Standard.Language; using Deltares.Standard.Reflection; using Deltares.Standard.TestUtils; using Deltares.Standard.Validation; using NUnit.Framework; namespace Deltares.Geotechnics.WaternetCreator.Tests { [TestFixture] public class LocationTest { [Test] public void TestValidateWaterLevelRiver() { var location = new Location { Surfaceline = new SurfaceLine2 { Geometry = new LocalizedGeometryPointString() }, WaternetCreationMode = WaternetCreationMode.CreateWaternet }; var messages = location.ValidateWaterLevelRiver(); Assert.IsTrue(messages.Any()); location.WaterLevelRiver = 55; messages = location.ValidateWaterLevelRiver(); Assert.IsFalse(messages.Any()); } [Test] public void ValidateSoilProfile_SoilProfile1DHas1InBetweenAquiferClusterContaining2Aquifers_NoValidationError() { // setup var soilProfile = new SoilProfile1D(); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = 1.0, Soil = new Soil { Name = "klei1" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = 0.0, Soil = new Soil { Name = "klei2" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -1.0, Soil = new Soil { Name = "zand1" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -2.0, Soil = new Soil { Name = "zand2" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -3.0, Soil = new Soil { Name = "klei3" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -4.0, Soil = new Soil { Name = "klei4" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -7.0, Soil = new Soil { Name = "klei5" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -8.0, Soil = new Soil { Name = "klei6" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -9.0, Soil = new Soil { Name = "zand3" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -10.0, Soil = new Soil { Name = "zand4" }, IsAquifer = true }); soilProfile.BottomLevel = -12.0; using (var location = new Location()) { using (var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new LocalizedGeometryPointString() }) { // Configure location such that validation is required: location.WaternetCreationMode = WaternetCreationMode.CreateWaternet; location.Surfaceline = surfaceLine; // Soil profile 1D normally required to perform validation: location.SoilProfile1D = soilProfile; // call var validationResults = location.ValidateSoilProfile(); // assert Assert.AreEqual(0, validationResults.Length); Assert.AreEqual("zand3", soilProfile.BottomAquiferLayer.Soil.Name); Assert.AreEqual("zand1", soilProfile.InBetweenAquiferLayer.Soil.Name); } } } [Test] public void ValidateSoilProfile_SoilProfile1DHas2InBetweenAquiferClustersWhichIsNotAllowed_ValidationError() { // setup var soilProfile = new SoilProfile1D(); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = 1.0, Soil = new Soil { Name = "klei1" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = 0.0, Soil = new Soil { Name = "klei2" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -1.0, Soil = new Soil { Name = "zand1" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -2.0, Soil = new Soil { Name = "zand2" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -3.0, Soil = new Soil { Name = "klei3" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -4.0, Soil = new Soil { Name = "klei4" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -5.0, Soil = new Soil { Name = "zand3" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -6.0, Soil = new Soil { Name = "zand4" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -7.0, Soil = new Soil { Name = "klei5" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -8.0, Soil = new Soil { Name = "klei6" }, IsAquifer = false }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -9.0, Soil = new Soil { Name = "zand5" }, IsAquifer = true }); soilProfile.Layers.Add(new SoilLayer1D { TopLevel = -10.0, Soil = new Soil { Name = "zand6" }, IsAquifer = true }); soilProfile.BottomLevel = -12.0; using (var location = new Location()) { using (var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new LocalizedGeometryPointString() }) { // Configure location such that validation is required: location.WaternetCreationMode = WaternetCreationMode.CreateWaternet; location.Surfaceline = surfaceLine; // Soil profile 1D normally required to perform validation: location.SoilProfile1D = soilProfile; // call var validationResults = location.ValidateSoilProfile(); // assert Assert.AreEqual(1, validationResults.Length); Assert.AreEqual("More than one in between aquifer present in soil profile. ", validationResults[0].Text); Assert.AreEqual("zand5", soilProfile.BottomAquiferLayer.Soil.Name); Assert.AreEqual("zand1", soilProfile.InBetweenAquiferLayer.Soil.Name); } } } [Test] public void ValidateSoilProfile_SoilProfile1DIsNull_NoValidationErrors() { // setup using (var location = new Location()) { using (var surfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new LocalizedGeometryPointString() }) { // Configure location such that validation is required: location.WaternetCreationMode = WaternetCreationMode.CreateWaternet; location.Surfaceline = surfaceLine; // Soil profile 1D normally required to perform validation: location.SoilProfile1D = null; // call var validationResults = location.ValidateSoilProfile(); // assert Assert.AreEqual(0, validationResults.Length); } } } [Test] public void ValidateSoilProfile_SurfaceLineIsNull_NoValidationErrors() { // setup using (var location = new Location()) { // Configure location such that validation is required: location.WaternetCreationMode = WaternetCreationMode.CreateWaternet; location.SoilProfile1D = new SoilProfile1D(); // Surface line normally required to perform validation: location.Surfaceline = null; // call var validationResults = location.ValidateSoilProfile(); // assert Assert.AreEqual(0, validationResults.Length); } } [Test] [TestCase(true, DikeSoilScenario.ClayDikeOnClay, false)] [TestCase(true, DikeSoilScenario.ClayDikeOnSand, false)] [TestCase(true, DikeSoilScenario.SandDikeOnClay, true)] [TestCase(true, DikeSoilScenario.SandDikeOnSand, true)] [TestCase(false, DikeSoilScenario.ClayDikeOnClay, false)] [TestCase(false, DikeSoilScenario.ClayDikeOnSand, false)] [TestCase(false, DikeSoilScenario.SandDikeOnClay, true)] [TestCase(false, DikeSoilScenario.SandDikeOnSand, true)] public void IsEnabled_DrainageConstructionPresent_HasCorrectEnabledState(bool initialDrainageConstructionPresentValue, DikeSoilScenario dikeSoilScenario, bool shouldBeEnabled) { // setup using (var location = new Location { DikeSoilScenario = dikeSoilScenario, DrainageConstructionPresent = initialDrainageConstructionPresentValue }) { // call var isEnabled = location.IsEnabled(location.GetMemberName(l => l.DrainageConstructionPresent)); // assert Assert.AreEqual(shouldBeEnabled, isEnabled, "Whether DrainageConstructionPresent is enabled depends on the DikeSoilScenario value."); } } [Test] [TestCase(true, DikeSoilScenario.ClayDikeOnClay, false)] [TestCase(true, DikeSoilScenario.ClayDikeOnSand, false)] [TestCase(true, DikeSoilScenario.SandDikeOnClay, true)] [TestCase(true, DikeSoilScenario.SandDikeOnSand, true)] [TestCase(false, DikeSoilScenario.ClayDikeOnClay, false)] [TestCase(false, DikeSoilScenario.ClayDikeOnSand, false)] [TestCase(false, DikeSoilScenario.SandDikeOnClay, false)] [TestCase(false, DikeSoilScenario.SandDikeOnSand, false)] public void SetDrainageConstructionPresent_DikeSoilScenarioSet_SetValueDependentOnDikeSoilScenario(bool drainageConstructionPresentValueToSet, DikeSoilScenario dikeSoilScenario, bool expectedValue) { // setup using (var location = new Location { DikeSoilScenario = dikeSoilScenario }) { // call location.DrainageConstructionPresent = drainageConstructionPresentValueToSet; // assert Assert.AreEqual(expectedValue, location.DrainageConstructionPresent, "DrainageConstructionPresent value depends on the DikeSoilScenario value."); } } [Test] public void WaterLevelRiver_SetValue_AlsoChangeHeadInPl3AndPl4() { // setup const double waterLevelRiver = 1.2; var location = new Location(); Assert.AreNotEqual(waterLevelRiver, location.HeadInPLLine3); Assert.AreNotEqual(waterLevelRiver, location.HeadInPLLine4); using (var counter = new PropertyChangeEventCounter()) using (var waterLevelRiverCounter = new PropertyChangeEventCounter { SenderFilter = location, PropertiesFilter = new[]{location.GetMemberName(l => l.WaterLevelRiver)} }) { // call location.WaterLevelRiver = waterLevelRiver; // assert Assert.AreEqual(waterLevelRiver, location.HeadInPLLine3); Assert.AreEqual(waterLevelRiver, location.HeadInPLLine4); Assert.AreEqual(1, counter.OnBeforeChangeCount); Assert.AreEqual(1, counter.OnAfterChangeCount); Assert.AreEqual(1, waterLevelRiverCounter.OnBeforeChangeCount); Assert.AreEqual(1, waterLevelRiverCounter.OnAfterChangeCount); } } [Test] public void ValidateAquifersOverCompleteWidth() { // setup var location = new Location(); location.SoilProfile2D = FactoryForSoilProfileTests.CreateSoilProfile2D(); location.DikeSoilScenario = DikeSoilScenario.SandDikeOnSand; // test correct situation for (int i = 0; i < location.SoilProfile2D.Surfaces.Count; i++ ) { location.SoilProfile2D.Surfaces[i].IsAquifer = i == 0; } Assert.AreEqual(0, location.ValidateAquifers().Length); // test no aquifer present foreach (SoilLayer2D layer in location.SoilProfile2D.Surfaces) { layer.IsAquifer = false; } Assert.AreEqual(1, location.ValidateAquifers().Length); // test aquifer in part in non-complete layer foreach (SoilLayer2D layer in location.SoilProfile2D.Surfaces) { layer.IsAquifer = true; } Assert.AreEqual(1, location.ValidateAquifers().Length); } [Test] public void ValidateAquifers_ClayDikeOnSand() { // setup var location = new Location(); location.SoilProfile2D = FactoryForSoilProfileTests.CreateSoilProfile2DClayDikeOnSand(); location.Surfaceline = FactoryForSoilProfileTests.CreateSurfacelineSimpleDike(); // test for Scenario Clay dike on clay location.DikeSoilScenario = DikeSoilScenario.ClayDikeOnClay; Assert.AreEqual(1, location.ValidateAquifers().Length); // test for Scenario Sand dike on clay location.DikeSoilScenario = DikeSoilScenario.SandDikeOnClay; Assert.AreEqual(0, location.ValidateAquifers().Length); // test for Scenario Clay dike on sand location.DikeSoilScenario = DikeSoilScenario.ClayDikeOnSand; Assert.AreEqual(0, location.ValidateAquifers().Length); // test for Scenario Sand dike on sand location.DikeSoilScenario = DikeSoilScenario.SandDikeOnSand; Assert.AreEqual(0, location.ValidateAquifers().Length); } private void SetLocationProperties(ClassWithLocationAsChild classWithLocationAsChild) { // Change values such that they are not the default values: classWithLocationAsChild.Location.AdjustPl3And4ForUplift = false; classWithLocationAsChild.Location.WaternetCreationMode = WaternetCreationMode.CreateWaternet; classWithLocationAsChild.Location.DikeSoilScenario = DikeSoilScenario.SandDikeOnClay; classWithLocationAsChild.Location.HeadInPLLine2Inwards = 7.7; classWithLocationAsChild.Location.HeadInPLLine2Outwards = 8.8; classWithLocationAsChild.Location.HeadInPLLine3 = 9.9; classWithLocationAsChild.Location.HeadInPLLine4 = 10.10; classWithLocationAsChild.Location.LeakageLengthInwardsPl3 = 17.17; classWithLocationAsChild.Location.LeakageLengthInwardsPl4 = 18.18; classWithLocationAsChild.Location.LeakageLengthOutwardsPl3 = 19.19; classWithLocationAsChild.Location.LeakageLengthOutwardsPl4 = 20.20; classWithLocationAsChild.Location.LocalXzpl1Line = CreateTestPhreaticLine(); classWithLocationAsChild.Location.NWOPhreaticAdaption = PhreaticAdaptionType.MakeEmpty; classWithLocationAsChild.Location.PenetrationLength = 21.21; classWithLocationAsChild.Location.PlLineCreationMethod = PlLineCreationMethod.DupuitDynamic; classWithLocationAsChild.Location.PlLineOffsetBelowDikeToeAtPolder = 22.22; classWithLocationAsChild.Location.PlLineOffsetBelowDikeTopAtPolder = 23.23; classWithLocationAsChild.Location.PlLineOffsetBelowDikeTopAtRiver = 24.24; classWithLocationAsChild.Location.PlLineOffsetBelowShoulderBaseInside = 25.25; classWithLocationAsChild.Location.SlopeDampingPiezometricHeightPolderSide = 26.26; classWithLocationAsChild.Location.SoilProfile1D = CreateTestSoilProfile1D(); classWithLocationAsChild.Location.SoilProfile2D = CreateTestSoilProfile2D(); classWithLocationAsChild.Location.Surfaceline = CreateTestSurfaceLine(); classWithLocationAsChild.Location.WaterLevelPolder = 27.27; classWithLocationAsChild.Location.WaterLevelRiver = 28.28; classWithLocationAsChild.Location.WaterLevelRiverAverage = 29.29; classWithLocationAsChild.Location.WaterLevelRiverLow = 30.30; classWithLocationAsChild.Location.X = 31.31; classWithLocationAsChild.Location.Y = 34.34; } private PhreaticLine CreateTestPhreaticLine() { var testPhreaticLine = new PhreaticLine { Name = "test pl 1 line" }; return testPhreaticLine; } private SoilProfile1D CreateTestSoilProfile1D() { var testSoilProfile1D = new SoilProfile1D { Name = "test profile 1D" }; return testSoilProfile1D; } private SoilProfile2D CreateTestSoilProfile2D() { var testSoilProfile2D = new SoilProfile2D { Name = "test profile 2D" }; return testSoilProfile2D; } private SurfaceLine2 CreateTestSurfaceLine() { var testSurfaceLine = new SurfaceLine2 { CharacteristicPoints = { GeometryMustContainPoint = true }, Geometry = new LocalizedGeometryPointString(), Name = "test surface line" }; return testSurfaceLine; } /// /// Water level at polder (0.15) is above surface level inside (X=45; Z=0.1). /// This situation is not allowed and should give an error message (no wternet created). /// [Test] public void LocationTest_WaterLevelPolderGreaterThanSurfaceLevelInside_ValidationError() { // setup var location = new Location(); location.Surfaceline = FactoryForSurfaceLineTests.CreateSurfaceLineBm4_01(); location.SoilProfile2D = FactoryForSoilProfileTests.Create2DProfileBenchmark4_01a(); location.DikeSoilScenario = DikeSoilScenario.ClayDikeOnClay; location.PlLineCreationMethod = PlLineCreationMethod.RingtoetsWti2017; location.HeadInPLLine2Inwards = 0.4; location.HeadInPLLine2Outwards = 0.8; location.LeakageLengthInwardsPl3 = 30; location.LeakageLengthInwardsPl4 = 50; location.LeakageLengthOutwardsPl3 = 50; location.LeakageLengthOutwardsPl4 = 800; location.PenetrationLength = 0.3; location.WaterLevelPolder = 0.15; location.WaterLevelRiver = 2.8; location.WaterLevelRiverAverage = 2.6; location.WaterLevelRiverLow = 0.8; location.PlLineOffsetBelowDikeTopAtRiver = 0.6; location.PlLineOffsetBelowDikeTopAtPolder = 1.3; location.PlLineOffsetBelowShoulderBaseInside = 0.1; location.PlLineOffsetBelowDikeToeAtPolder = 0.2; location.AdjustPl3And4ForUplift = true; location.MinimumLevelPhreaticLineAtDikeTopPolder = -5; location.MinimumLevelPhreaticLineAtDikeTopRiver = -5; location.WaternetCreationMode = WaternetCreationMode.CreateWaternet; // output var waternetCreator = new WaternetCreator(); var waternet = new Waternet(); waternetCreator.UpdateWaternet(waternet, location); location.Validate(); // assert Assert.AreEqual(2, location.Validate().Length); Assert.AreEqual(ValidationResultType.Warning, location.Validate()[0].MessageType); Assert.AreEqual(LocalizationManager.GetTranslatedText(typeof(Location), "TrafficLoadNotPresent"), location.Validate()[0].Text); Assert.AreEqual(ValidationResultType.Error, location.Validate()[1].MessageType); Assert.AreEqual(LocalizationManager.GetTranslatedText(typeof(Location), "WaterLevelPolderGreaterThanSurfaceLevelInside"), location.Validate()[1].Text); } private class ClassWithLocationAsChild : IDisposable { public Location Location { get; set; } public void Dispose() {} } } }