Index: DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/OperationalStabilityProfile1DTests.cs =================================================================== diff -u -r5976 -r5979 --- DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/OperationalStabilityProfile1DTests.cs (.../OperationalStabilityProfile1DTests.cs) (revision 5976) +++ DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/OperationalStabilityProfile1DTests.cs (.../OperationalStabilityProfile1DTests.cs) (revision 5979) @@ -20,14 +20,14 @@ // All rights reserved. using System.Collections.Generic; -using System.Drawing; using System.IO; using System.Linq; using Deltares.DamEngine.Data.Standard; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlInput; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; +using Deltares.MacroStability.Io; using Deltares.MacroStability.Io.XmlInput; using KellermanSoftware.CompareNetObjects; using NUnit.Framework; @@ -42,39 +42,17 @@ /// Constants for SensorType /// private const uint sourceTypeIgnore = 0; + private const uint sourceTypeLocationData = 1; private const uint sourceTypeSensor = 2; - - public class SensorConfiguration - { - public uint SourceTypePl1OuterWaterLevel { get; set; } = sourceTypeSensor; - public double Pl1OuterWaterLevel { get; set; } = 0.0; - public uint SourceTypePl1PlLineOffsetBelowDikeTopAtRiver { get; set; } = sourceTypeIgnore; - public double Pl1PlLineOffsetBelowDikeTopAtRiver { get; set; } = 0.0; - public uint SourceTypePl1PlLineOffsetBelowDikeTopAtPolder { get; set; } = sourceTypeIgnore; - public double Pl1PlLineOffsetBelowDikeTopAtPolder { get; set; } = 0.0; - public uint SourceTypePl1PlLineOffsetBelowShoulderBaseInside { get; set; } = sourceTypeIgnore; - public double Pl1PlLineOffsetBelowShoulderBaseInside { get; set; } = 0.0; - public uint SourceTypePl1PlLineOffsetBelowDikeToeAtPolder { get; set; } = sourceTypeIgnore; - public double Pl1PlLineOffsetBelowDikeToeAtPolder { get; set; } = 0.0; - public uint SourceTypePl1PolderLevel { get; set; } = sourceTypeSensor; - public double PlPolderLevel { get; set; } = 0.0; - public uint SourceTypePl3 { get; set; } = sourceTypeLocationData; - public double HeadPl3 { get; set; } = 0.0; - public uint SourceTypePl4 { get; set; } = sourceTypeLocationData; - public double HeadPl4 { get; set; } = 0.0; - } - public class PlLinePoints - { - public List Points { get; set; } - } + public static IEnumerable AddTestCases { get { yield return new TestCaseData( // This is the case that all values are taken from the location data - new SensorConfiguration() + new SensorConfiguration { SourceTypePl1OuterWaterLevel = sourceTypeLocationData, Pl1OuterWaterLevel = -0.1, @@ -93,7 +71,7 @@ SourceTypePl4 = sourceTypeLocationData, HeadPl4 = 0.0 }, - new PlLinePoints() + new PlLinePoints { Points = [ @@ -131,27 +109,27 @@ }).SetName("Only location data"); yield return new TestCaseData( // This is the case that all values are taken from the sensor data - new SensorConfiguration() - { - SourceTypePl1OuterWaterLevel = sourceTypeSensor, - Pl1OuterWaterLevel = -0.1, - SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = sourceTypeIgnore, - Pl1PlLineOffsetBelowDikeTopAtRiver = 1.1, - SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = sourceTypeIgnore, - Pl1PlLineOffsetBelowDikeTopAtPolder = 1.2, - SourceTypePl1PlLineOffsetBelowShoulderBaseInside = sourceTypeIgnore, - Pl1PlLineOffsetBelowShoulderBaseInside = 0.0, - SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = sourceTypeIgnore, - Pl1PlLineOffsetBelowDikeToeAtPolder = 1.4, - SourceTypePl1PolderLevel = sourceTypeSensor, - PlPolderLevel = -2.0, - SourceTypePl3 = sourceTypeIgnore, - HeadPl3 = -3.0, - SourceTypePl4 = sourceTypeIgnore, - HeadPl4 = 0.0 - }, - new PlLinePoints() + new SensorConfiguration { + SourceTypePl1OuterWaterLevel = sourceTypeSensor, + Pl1OuterWaterLevel = -0.1, + SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = sourceTypeIgnore, + Pl1PlLineOffsetBelowDikeTopAtRiver = 1.1, + SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = sourceTypeIgnore, + Pl1PlLineOffsetBelowDikeTopAtPolder = 1.2, + SourceTypePl1PlLineOffsetBelowShoulderBaseInside = sourceTypeIgnore, + Pl1PlLineOffsetBelowShoulderBaseInside = 0.0, + SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = sourceTypeIgnore, + Pl1PlLineOffsetBelowDikeToeAtPolder = 1.4, + SourceTypePl1PolderLevel = sourceTypeSensor, + PlPolderLevel = -2.0, + SourceTypePl3 = sourceTypeIgnore, + HeadPl3 = -3.0, + SourceTypePl4 = sourceTypeIgnore, + HeadPl4 = 0.0 + }, + new PlLinePoints + { Points = [ new Point2DType @@ -203,7 +181,7 @@ [TestCaseSource(nameof(AddTestCases))] public void GivenStabilityInsideProfile1DProject_WhenCalculatingWithVariatonsOnSpecifiedSensorLocationData_ThenExpectedResultIsGenerated(SensorConfiguration sensorConfiguration, PlLinePoints plLinePoints) { - string projectPath = "SensorProfile1DTests"; + var projectPath = "SensorProfile1DTests"; const string calcDir = "DAMLive.Calc"; const string testFilesLocation = @".\TestFiles\Operational\SensorProfile1DTests\"; string inputFilename = testFilesLocation + "CalculateStabilityInsideBishopGrid1InputFile.xml"; @@ -212,48 +190,27 @@ { Directory.Delete(calcDir, true); // delete previous results } + Input input = DamXmlSerialization.LoadInputFromXmlFile(inputFilename); input.ProjectPath = projectPath; - var location = input.Locations[0]; + Location location = input.Locations[0]; FillSensorLocation(input.SensorData.SensorLocations[0], location, sensorConfiguration); string inputString = DamXmlSerialization.SaveInputAsXmlString(input); DamXmlSerialization.SaveInputAsXmlFile(inputFilename, input); Output output = GeneralHelper.RunAfterInputValidation(inputString, true, outputFilename); Assert.That(output, Is.Not.Null); // Read the kernel input data from the input file - string kernelInputFilename = $"{projectPath}\\DAMLive.Calc\\Stability\\Bishop\\Dik(dike)_Loc(Purmer_PU0042+00_K)_Stp(0)_Mdl(Bishop)_2016-03-02T03_10_00_Pro(Purmer_PU0042+00K).skx"; - FullInputModelType expectedMacrostabilityInput = MacroStability.Io.MacroStabilityXmlSerialization.LoadInputFromXmlFile(kernelInputFilename); + var kernelInputFilename = $"{projectPath}\\DAMLive.Calc\\Stability\\Bishop\\Dik(dike)_Loc(Purmer_PU0042+00_K)_Stp(0)_Mdl(Bishop)_2016-03-02T03_10_00_Pro(Purmer_PU0042+00K).skx"; + FullInputModelType expectedMacrostabilityInput = MacroStabilityXmlSerialization.LoadInputFromXmlFile(kernelInputFilename); const double tolerance = 0.0005; List phreaticLine = expectedMacrostabilityInput.StabilityModel.ConstructionStages[0].Waternet.PhreaticLine.WaternetLine.Points.ToList(); - foreach (var point in plLinePoints.Points) + foreach (Point2DType point in plLinePoints.Points) { bool pointExists = phreaticLine.Any(p => p.X.IsNearEqual(point.X, tolerance) && p.Z.IsNearEqual(point.Z, tolerance)); Assert.That(pointExists, Is.True, $"The expected point x={point.X}, z={point.X} was not found in the phreatic line."); } } - private void FillSensorLocation(SensorLocation sensorDataSensorLocation, Location location, SensorConfiguration sensorConfiguration) - { - sensorDataSensorLocation.SourceTypePl1WaterLevelAtRiver = sensorConfiguration.SourceTypePl1OuterWaterLevel; - location.DesignScenarios[0].RiverLevel = sensorConfiguration.Pl1OuterWaterLevel; - sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = sensorConfiguration.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver; - location.DesignScenarios[0].PlLineOffsetBelowDikeTopAtRiver = sensorConfiguration.Pl1PlLineOffsetBelowDikeTopAtRiver; - sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = sensorConfiguration.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder; - location.DesignScenarios[0].PlLineOffsetBelowDikeTopAtPolder = sensorConfiguration.Pl1PlLineOffsetBelowDikeTopAtPolder; - sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside = sensorConfiguration.SourceTypePl1PlLineOffsetBelowShoulderBaseInside; - location.DesignScenarios[0].PlLineOffsetBelowShoulderBaseInside = sensorConfiguration.Pl1PlLineOffsetBelowShoulderBaseInside; - sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = sensorConfiguration.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder; - location.DesignScenarios[0].PlLineOffsetBelowDikeToeAtPolder = sensorConfiguration.Pl1PlLineOffsetBelowDikeToeAtPolder; - sensorDataSensorLocation.SourceTypePl1WaterLevelAtPolder = sensorConfiguration.SourceTypePl1PolderLevel; - location.DesignScenarios[0].PolderLevel = sensorConfiguration.PlPolderLevel; - sensorDataSensorLocation.SourceTypePl3 = sensorConfiguration.SourceTypePl3; - location.DesignScenarios[0].HeadPl3 = sensorConfiguration.HeadPl3; - location.DesignScenarios[0].HeadPl3Specified = true; - sensorDataSensorLocation.SourceTypePl4 = sensorConfiguration.SourceTypePl4; - location.DesignScenarios[0].HeadPl4Specified = true; - location.DesignScenarios[0].HeadPl4 = sensorConfiguration.HeadPl4; - } - [Test, Category(Categories.Slow)] // Following testcase based on the DamLive test Deltares.DamLive.Tests.StabilityInsideBishopGridTest // "Deltares.DamLive.Tests\TestData\IntegrationTests\StabilityInsideBishopGrid\DAMLive.damx" @@ -285,6 +242,7 @@ { baseOutputName += "_UseLocationData"; } + string projectPath = baseOutputName; string inputFilename = baseName + "InputFile.xml"; string outputFilename = baseOutputName + "OutputFile.xml"; @@ -309,27 +267,29 @@ if (isUseSensorLocationData) { // Change the source type of Pl1 offset below diketop location data (=1) - inputString = XmlAdapter.ChangeValueInXml(inputString, "SourceTypePl1PlLineOffsetBelowDikeTopAtPolder", "1"); - inputString = XmlAdapter.ChangeValueInXml(inputString, "PlLineOffsetBelowDikeTopAtPolder", "1.1"); - } + inputString = XmlAdapter.ChangeValueInXml(inputString, "SourceTypePl1PlLineOffsetBelowDikeTopAtPolder", "1"); + inputString = XmlAdapter.ChangeValueInXml(inputString, "PlLineOffsetBelowDikeTopAtPolder", "1.1"); + } + // When // Run calculation Output actualOutput = GeneralHelper.RunAfterInputValidation(inputString, true, outputFilename); if (isUseSensorLocationData) { // Read the kernel input data from the input file - string kernelInputFilename = $"{baseName}_UseLocationData\\DAMLive.Calc\\Stability\\Bishop\\Dik(dike)_Loc(Purmer_PU0042+00_K)_Stp(0)_Mdl(Bishop)_2016-03-02T03_10_00_Pro(Purmer_PU0042+00K).skx"; - FullInputModelType expectedMacrostabilityInput = MacroStability.Io.MacroStabilityXmlSerialization.LoadInputFromXmlFile(kernelInputFilename); + var kernelInputFilename = $"{baseName}_UseLocationData\\DAMLive.Calc\\Stability\\Bishop\\Dik(dike)_Loc(Purmer_PU0042+00_K)_Stp(0)_Mdl(Bishop)_2016-03-02T03_10_00_Pro(Purmer_PU0042+00K).skx"; + FullInputModelType expectedMacrostabilityInput = MacroStabilityXmlSerialization.LoadInputFromXmlFile(kernelInputFilename); List phreaticLine = expectedMacrostabilityInput.StabilityModel.ConstructionStages[0].Waternet.PhreaticLine.WaternetLine.Points.ToList(); - var expectedPoint = new Point2DType() + var expectedPoint = new Point2DType { X = expectedPlLineXValue, Z = expectedPlLineZValue }; const double tolerance = 0.0005; bool pointExists = phreaticLine.Any(p => p.X.IsNearEqual(expectedPoint.X, tolerance) && p.Z.IsNearEqual(expectedPoint.Z, tolerance)); Assert.That(pointExists, Is.True, "The expected point was not found in the phreatic line."); - } + } + // Then // Compare output Assert.Multiple(() => @@ -341,6 +301,53 @@ CompareOutput(expectedOutput, actualOutput); } + public class SensorConfiguration + { + public uint SourceTypePl1OuterWaterLevel { get; set; } = sourceTypeSensor; + public double Pl1OuterWaterLevel { get; set; } + public uint SourceTypePl1PlLineOffsetBelowDikeTopAtRiver { get; set; } = sourceTypeIgnore; + public double Pl1PlLineOffsetBelowDikeTopAtRiver { get; set; } + public uint SourceTypePl1PlLineOffsetBelowDikeTopAtPolder { get; set; } = sourceTypeIgnore; + public double Pl1PlLineOffsetBelowDikeTopAtPolder { get; set; } + public uint SourceTypePl1PlLineOffsetBelowShoulderBaseInside { get; set; } = sourceTypeIgnore; + public double Pl1PlLineOffsetBelowShoulderBaseInside { get; set; } + public uint SourceTypePl1PlLineOffsetBelowDikeToeAtPolder { get; set; } = sourceTypeIgnore; + public double Pl1PlLineOffsetBelowDikeToeAtPolder { get; set; } + public uint SourceTypePl1PolderLevel { get; set; } = sourceTypeSensor; + public double PlPolderLevel { get; set; } + public uint SourceTypePl3 { get; set; } = sourceTypeLocationData; + public double HeadPl3 { get; set; } + public uint SourceTypePl4 { get; set; } = sourceTypeLocationData; + public double HeadPl4 { get; set; } + } + + public class PlLinePoints + { + public List Points { get; set; } + } + + private void FillSensorLocation(SensorLocation sensorDataSensorLocation, Location location, SensorConfiguration sensorConfiguration) + { + sensorDataSensorLocation.SourceTypePl1WaterLevelAtRiver = sensorConfiguration.SourceTypePl1OuterWaterLevel; + location.DesignScenarios[0].RiverLevel = sensorConfiguration.Pl1OuterWaterLevel; + sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = sensorConfiguration.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver; + location.DesignScenarios[0].PlLineOffsetBelowDikeTopAtRiver = sensorConfiguration.Pl1PlLineOffsetBelowDikeTopAtRiver; + sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = sensorConfiguration.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder; + location.DesignScenarios[0].PlLineOffsetBelowDikeTopAtPolder = sensorConfiguration.Pl1PlLineOffsetBelowDikeTopAtPolder; + sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside = sensorConfiguration.SourceTypePl1PlLineOffsetBelowShoulderBaseInside; + location.DesignScenarios[0].PlLineOffsetBelowShoulderBaseInside = sensorConfiguration.Pl1PlLineOffsetBelowShoulderBaseInside; + sensorDataSensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = sensorConfiguration.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder; + location.DesignScenarios[0].PlLineOffsetBelowDikeToeAtPolder = sensorConfiguration.Pl1PlLineOffsetBelowDikeToeAtPolder; + sensorDataSensorLocation.SourceTypePl1WaterLevelAtPolder = sensorConfiguration.SourceTypePl1PolderLevel; + location.DesignScenarios[0].PolderLevel = sensorConfiguration.PlPolderLevel; + sensorDataSensorLocation.SourceTypePl3 = sensorConfiguration.SourceTypePl3; + location.DesignScenarios[0].HeadPl3 = sensorConfiguration.HeadPl3; + location.DesignScenarios[0].HeadPl3Specified = true; + sensorDataSensorLocation.SourceTypePl4 = sensorConfiguration.SourceTypePl4; + location.DesignScenarios[0].HeadPl4Specified = true; + location.DesignScenarios[0].HeadPl4 = sensorConfiguration.HeadPl4; + } + private static void CompareOutput(Output expected, Output actual) { var compare = new CompareLogic Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorPLLineCreatorTest.cs =================================================================== diff -u -r5977 -r5979 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorPLLineCreatorTest.cs (.../SensorPLLineCreatorTest.cs) (revision 5977) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorPLLineCreatorTest.cs (.../SensorPLLineCreatorTest.cs) (revision 5979) @@ -1290,7 +1290,7 @@ location.CurrentScenario = scenario; return location; } - + private void SetUpSensorData(double riverLevel, out IDictionary sensorValues, out SensorLocation sensorLocation) { var surfaceLine = new SurfaceLine2 @@ -1387,7 +1387,6 @@ sensorLocation = location.SensorLocation; } - #region Setup [SetUp] Index: DamEngine/trunk/src/Deltares.DamEngine.Data/General/Sensors/SensorLocation.cs =================================================================== diff -u -r5971 -r5979 --- DamEngine/trunk/src/Deltares.DamEngine.Data/General/Sensors/SensorLocation.cs (.../SensorLocation.cs) (revision 5971) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/General/Sensors/SensorLocation.cs (.../SensorLocation.cs) (revision 5979) @@ -109,7 +109,7 @@ { get { - return (Location != null) ? Location.Name : string.Empty; + return Location != null ? Location.Name : string.Empty; } } Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorLocationTests.cs =================================================================== diff -u -r5977 -r5979 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorLocationTests.cs (.../SensorLocationTests.cs) (revision 5977) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorLocationTests.cs (.../SensorLocationTests.cs) (revision 5979) @@ -30,7 +30,7 @@ [TestFixture] public class SensorLocationTest { - readonly Location location = new Location(); + private readonly Location location = new Location(); #region Helper methods